Skip to content

Commit

Permalink
Merge pull request #373 from Saranya-jena/cp-3.0.0
Browse files Browse the repository at this point in the history
Cherry pick: Changes added for 3.0.0 release
  • Loading branch information
amityt authored Sep 27, 2023
2 parents 6404262 + 2be7824 commit 3d62022
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 119 deletions.
1 change: 0 additions & 1 deletion app/client/src/components/ExperimentInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function ExperimentInfo(props: ExpInfoProps) {
<div className={classes.expDesc}>
<ReactMarkdown source={description} />
</div>
{videoURL && <VideoFrame width={"775px"} src={videoEmbed || ""} />}
</div>
);
}
7 changes: 5 additions & 2 deletions app/client/src/components/UsefulLinks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ export function UsefulLinks(props: UsefulLinks) {
}
return (
<div className={classes.mainDiv}>
{createLinks("Useful Links", props.links)}
{createMaintainers(props.maintainers)}
{props.links.length > 0 && createLinks("Useful Links", props.links)}
{props.maintainers.length > 0 &&
createMaintainers(props.maintainers)}
{props.platforms &&
props.platforms.length > 0 &&
props.platforms &&
createPlatformData("Platforms", props.platforms)}
{props.maturity && createStaticData("Maturity", [props.maturity])}
</div>
Expand Down
65 changes: 0 additions & 65 deletions app/client/src/pages/ExperimentPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSelector } from "react-redux";
import {
BackButton,
ExperimentInfo,
InstallChaos,
UsefulLinks,
ExperimentHeader,
} from "../../components";
Expand Down Expand Up @@ -60,7 +59,6 @@ function ExperimentPage(props: any) {
chartGroup.experiments.filter(
(e) => e.metadataName === chartId
)[0];

React.useEffect(() => {
window.scrollTo(0, 0);
}, []);
Expand Down Expand Up @@ -142,26 +140,6 @@ function ExperimentPage(props: any) {
classes.horizontalLine
}
/>
<div>
<div className={classes.note}>
PRE-REQUISITE:
</div>
<div>
<a
href="https://docs.litmuschaos.io/docs/getting-started/installation/"
target="_"
>
Install Litmus Operator
</a>
: a tool for injecting Chaos
Experiments
</div>
</div>
<hr
className={
classes.horizontalLine
}
/>
</div>
</div>
{/* Useful Links Section */}
Expand All @@ -174,49 +152,6 @@ function ExperimentPage(props: any) {
/>
</div>
</div>
{/* Install Chaos Section */}
<div className={classes.installLinks}>
<InstallChaos
title="Install this Chaos Experiment"
description="You can install the Chaos Experiment using the following command"
yamlLink={`kubectl apply -f ${hubUrl}`}
/>
<InstallChaos
description="In case you want to customize or download the yaml you can use from the link below"
yamlLink={hubUrl}
editBtn={true}
/>
{rbacUrl && (
<>
<InstallChaos
title="Setup Service Account (RBAC)"
description="Create a service account using the following command"
yamlLink={`kubectl apply -f ${rbacUrl}`}
/>
<InstallChaos
description="In case you want to customize or download the yaml you can use from the link below"
yamlLink={rbacUrl}
editBtn={true}
/>
</>
)}
{engineUrl && (
<>
<InstallChaos
title="Sample Chaos Engine"
description="Edit and copy the sample Chaos Engine yaml according to your application needs"
yamlLink={engineUrl}
editBtn={true}
/>
<InstallChaos
description="Once you download the yaml you can apply the yaml using the below command"
yamlLink={
"kubectl apply -f <chaosengine-yaml-manifest>"
}
/>
</>
)}
</div>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/redux/reducers/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const chartData = createReducer<ChartData>(initialState, {
links: spec.Links
? spec.Links.map((l: any) => ({
name: l.Name,
url: l.Url,
url: l.URL,
}))
: [],
chaosExpCRDLink: spec.ChaosExpCRDLink,
Expand Down Expand Up @@ -82,7 +82,7 @@ export const chartData = createReducer<ChartData>(initialState, {
links: spec.Links
? spec.Links.map((l: any) => ({
name: l.Name,
url: l.Url,
url: l.URL,
}))
: [],
chaosExpCRDLink: spec.ChaosExpCRDLink,
Expand Down
40 changes: 24 additions & 16 deletions app/server/controller/handler/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@ limitations under the License.
package handler

type Chart struct {
ApiVersion string `yaml:"apiVersion"`
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
PackageInfo PackageInformation `yaml:"packageInfo"`
Experiments []Chart `yaml:"experiments"`
Experiments []Chart `yaml:"experiments" `
}

type Maintainer struct {
Name string
Email string
Name string `yaml:"name"`
Email string `yaml:"email"`
}

type Link struct {
Name string
Url string
Name string `yaml:"name"`
URL string `yaml:"url"`
}

type Faults struct {
Name string `yaml:"name"`
DisplayName string `json:"displayName"`
Description string `yaml:"description"`
Plan []string `json:"plan"`
}

type Metadata struct {
Expand All @@ -51,19 +58,20 @@ type Annotation struct {
}

type Spec struct {
DisplayName string `yaml:"displayName"`
CategoryDescription string `yaml:"categoryDescription"`
Keywords []string `yaml:"keywords"`

Maturity string `yaml:"maturity"`
Maintainers []Maintainer `yaml:"maintainers"`
MinKubeVersion string `yaml:"minKubeVersion"`
Provider struct {
DisplayName string `yaml:"displayName"`
CategoryDescription string `yaml:"categoryDescription"`
Plan []string `json:"plan"`
Keywords []string `yaml:"keywords"`
Maturity string `yaml:"maturity"`
Maintainers []Maintainer `yaml:"maintainers"`
MinKubeVersion string `yaml:"minKubeVersion"`
Scenarios []string `yaml:"scenarios"`
Provider struct {
Name string `yaml:"name"`
} `yaml:"provider"`
Links []Link `yaml:"links"`

Links []Link `yaml:"links"`
Experiments []string `yaml:"experiments"`
Faults []Faults `yaml:"faults"`
ChaosExpCRDLink string `yaml:"chaosexpcrdlink"`
Platforms []string `yaml:"platforms"`
ChaosType string `yaml:"chaosType"`
Expand Down
37 changes: 17 additions & 20 deletions app/server/controller/handler/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import (
var ChaosChartPath = os.Getenv("GOPATH") + "/src/github.com/litmuschaos/charthub.litmuschaos.io/app/client/public/chaos-charts/"
var githubData = os.Getenv("GOPATH") + "/src/github.com/litmuschaos/charthub.litmuschaos.io/app/client/public/githubData/"

/* pathParser reads the path in the csv file <path> forms the system-path <fileLookedPath>
and returns the file
/*
pathParser reads the path in the csv file <path> forms the system-path <fileLookedPath>
and returns the file
*/
func pathParser(path string) ([]byte, error) {
var fileLookedPath = ChaosChartPath + path
Expand All @@ -51,10 +52,10 @@ func pathParser(path string) ([]byte, error) {
return fileContent, nil
}

//GetIconHandler takes the experiment group and icon file required and returns the specific icon file
// GetIconHandler takes the experiment group and icon file required and returns the specific icon file
func GetIconHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
img, err := os.Open(ChaosChartPath + vars["version"] + "/charts/" + vars["expGroup"] + "/icons/" + vars["iconFile"])
img, err := os.Open(ChaosChartPath + vars["version"] + "/faults/" + vars["expGroup"] + "/icons/" + vars["iconFile"])
responseStatusCode := 200
if err != nil {
responseStatusCode = 500
Expand All @@ -68,7 +69,7 @@ func GetIconHandler(w http.ResponseWriter, r *http.Request) {
io.Copy(w, img)
}

//FileHandler takes out the file paths from the query params respectives URLs
// FileHandler takes out the file paths from the query params respectives URLs
func FileHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
filePath, ok := r.URL.Query()["file"]
Expand Down Expand Up @@ -101,7 +102,7 @@ func GetAnalyticsData(w http.ResponseWriter, r *http.Request) {
// GetChart is used to create YAML objects from experiments' directories from the respective charts'
func GetChart(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
filePath := ChaosChartPath + vars["version"] + "/charts/" + vars["chartId"]
filePath := ChaosChartPath + vars["version"] + "/faults/" + vars["chartId"]
chart, err := getYAMLFileContent(filePath)
response, err := json.Marshal(chart)
responseStatusCode := 200
Expand Down Expand Up @@ -135,45 +136,41 @@ func readPackageFile(path string) (PackageInformation, error) {
return packageInfo, err
}

func readExperimentFile(path string) (Chart, error) {
var experiment Chart
func readExperimentFile(path string) (*Chart, error) {
var experiment *Chart
experimentFile, err := ioutil.ReadFile(path)
if err != nil {
return experiment, fmt.Errorf("file path of the, err: %+v", err)
return nil, fmt.Errorf("file path of the, err: %+v", err)
}
if yaml.Unmarshal([]byte(experimentFile), &experiment) != nil {
return experiment, err
if yaml.Unmarshal(experimentFile, &experiment) != nil {
return nil, err
}
return experiment, nil
}
func getYAMLFileContent(fileLocation string) (Chart, error) {
chartPathSplitted := strings.Split(fileLocation, "/")
CSVFilePath := fileLocation + "/" + chartPathSplitted[len(chartPathSplitted)-1] + ".chartserviceversion.yaml"
packageFilePath := fileLocation + "/" + chartPathSplitted[len(chartPathSplitted)-1] + ".package.yaml"
chart, err := readCSVFile(CSVFilePath)
if err != nil {
return chart, err
}
packageInfo, err := readPackageFile(packageFilePath)
if err != nil {
return chart, err
}
chart.PackageInfo = packageInfo
for _, exp := range packageInfo.Experiments {
for _, exp := range chart.Spec.Faults {
experimentFilePath := fileLocation + "/" + exp.Name + "/" + exp.Name + ".chartserviceversion.yaml"
experiment, err := readExperimentFile(experimentFilePath)
if err != nil {
log.Error(err)
}
chart.Experiments = append(chart.Experiments, experiment)
if experiment != nil {
chart.Experiments = append(chart.Experiments, *experiment)
}
}
return chart, nil
}

// GetCharts is used to create list of YAML objects from charts' directories
func GetCharts(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
files, err := filepath.Glob(ChaosChartPath + vars["version"] + "/charts/*")
files, err := filepath.Glob(ChaosChartPath + vars["version"] + "/faults/*")
if err != nil {
log.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions app/server/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/litmuschaos/charthub.litmuschaos.io/app/server

go 1.19
go 1.20

require (
github.com/gorilla/mux v1.7.3
Expand Down Expand Up @@ -28,7 +28,7 @@ require (
go.opencensus.io v0.22.3 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20200403120447-c50568487044 // indirect
Expand Down
3 changes: 1 addition & 2 deletions app/server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d h1:nc5K6ox/4lTFbMVSL9WRR81ixkcwXThoiF6yf+R9scA=
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 4 additions & 4 deletions app/server/pkg/community/github/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Handler() {
}
}

//updateGithubStars will get the github stars count for litmus repository using github APIs
// updateGithubStars will get the github stars count for litmus repository using github APIs
func updateGithubStars() error {
response, err := http.Get(githubApi + organization + "/" + repoName)
if err != nil {
Expand All @@ -60,9 +60,9 @@ func updateGithubStars() error {
return nil
}

//updateExpCount updates will get the chaos experiment count from chaos-charts repo
// updateExpCount updates will get the chaos experiment count from chaos-charts repo
func updateExpCount() error {
response, err := http.Get(githubApi + organization + "/chaos-charts/contents/charts")
response, err := http.Get(githubApi + organization + "/chaos-charts/contents/faults")
if err != nil {
return fmt.Errorf("error while getting experiment count, err :%s", err)
}
Expand All @@ -75,7 +75,7 @@ func updateExpCount() error {
count := 0
for _, dirD := range dir {
if dirD["type"].(string) == "dir" {
response, err = http.Get(githubApi + organization + "/chaos-charts/contents/charts/" + dirD["name"].(string))
response, err = http.Get(githubApi + organization + "/chaos-charts/contents/faults/" + dirD["name"].(string))
if err != nil {
return fmt.Errorf("error while getting experiment count, err :%s", err)
}
Expand Down
17 changes: 12 additions & 5 deletions app/server/pkg/gitops/gitwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,29 @@ func (c GitConfig) getChaosChartVersion() ([]string, error) {
}
versions := []*version.Version{}
versionStrings := []string{}

versionLimiter, err := version.NewVersion("3.1.0")
if err != nil {
return nil, fmt.Errorf("unable to get limit version object, err: %+v", err)
}
err = tagrefs.ForEach(func(t *plumbing.Reference) error {
v, err := version.NewVersion(t.Name().Short())
if err!=nil{
if err != nil {
return fmt.Errorf("unable to get version object, err: %+v", err)
}
versions = append(versions,v)

if v.GreaterThanOrEqual(versionLimiter) {
versions = append(versions, v)
}

return nil
})
if err != nil {
return nil, fmt.Errorf("unable to get each tag reference, err: %+v", err)
}

sort.Sort(sort.Reverse(version.Collection(versions)))
for _,v := range versions{
versionStrings = append(versionStrings,v.String())
for _, v := range versions {
versionStrings = append(versionStrings, v.String())
}
versionStrings = append(versionStrings, defaultBranch)

Expand Down

0 comments on commit 3d62022

Please sign in to comment.