Skip to content

Commit

Permalink
Added branch and tag clone functionality and env for branch/tag for M…
Browse files Browse the repository at this point in the history
…yHub (#2724)

* Added branch and tag clone functionality and env for branch/tag for MyHub

Signed-off-by: Amit Kumar Das <amit@chaosnative.com>
  • Loading branch information
amityt committed Apr 20, 2021
1 parent 5d5002d commit 7494b0b
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Expand Up @@ -5,7 +5,7 @@ on:
- master
- v*
tags:
- '*'
- "*"
jobs:
backend-checks:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
source env-vars
cd litmus-portal/frontend
timestamp=`date "+%s"`
docker build . -f Dockerfile -t ${{ secrets.REPONAME }}/${FRONTEND_IMAGE}:${IMG_TAG} --build-arg REACT_APP_KB_CHAOS_VERSION=${IMG_TAG} --build-arg REACT_APP_BUILD_TIME="$timestamp"
docker build . -f Dockerfile -t ${{ secrets.REPONAME }}/${FRONTEND_IMAGE}:${IMG_TAG} --build-arg REACT_APP_KB_CHAOS_VERSION=${IMG_TAG} --build-arg REACT_APP_BUILD_TIME="$timestamp" --build-arg REACT_APP_HUB_BRANCH_NAME="v1.13.x"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand All @@ -228,4 +228,4 @@ jobs:
then
source env-vars
docker push ${{ secrets.REPONAME }}/${FRONTEND_IMAGE}:${IMG_TAG}
fi
fi
2 changes: 2 additions & 0 deletions docs/2.0.0-Beta/litmus-2.0.0-Beta.yaml
Expand Up @@ -183,6 +183,8 @@ spec:
value: "litmus-ingress"
- name: CONTAINER_RUNTIME_EXECUTOR
value: "k8sapi"
- name: HUB_BRANCH_NAME
value: "v1.13.x"
ports:
- containerPort: 8080
imagePullPolicy: Always
Expand Down
2 changes: 2 additions & 0 deletions docs/2.0.0-Beta/litmus-namespaced-2.0.0-Beta.yaml
Expand Up @@ -179,6 +179,8 @@ spec:
value: "litmuschaos/chaos-exporter:1.13.3"
- name: CONTAINER_RUNTIME_EXECUTOR
value: "k8sapi"
- name: HUB_BRANCH_NAME
value: "v1.13.x"
ports:
- containerPort: 8080
imagePullPolicy: Always
Expand Down
2 changes: 2 additions & 0 deletions litmus-portal/cluster-k8s-manifest.yml
Expand Up @@ -183,6 +183,8 @@ spec:
value: "litmus-ingress"
- name: CONTAINER_RUNTIME_EXECUTOR
value: "k8sapi"
- name: HUB_BRANCH_NAME
value: "v1.13.x"
ports:
- containerPort: 8080
imagePullPolicy: Always
Expand Down
1 change: 1 addition & 0 deletions litmus-portal/frontend/Dockerfile
Expand Up @@ -7,6 +7,7 @@ LABEL maintainer="LitmusChaos"

ARG REACT_APP_KB_CHAOS_VERSION
ARG REACT_APP_BUILD_TIME
ARG REACT_APP_HUB_BRANCH_NAME

# Checking environment variables
RUN env
Expand Down
27 changes: 9 additions & 18 deletions litmus-portal/frontend/src/components/PredifinedWorkflows/data.ts
Expand Up @@ -4,12 +4,9 @@ export default [
title: 'sock-shop-chaos',
chaosinfra: false,
urlToIcon: '/icons/sock-shop.png',
chaosWkfCRDLink:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/sock-shop-demo/usingCmdProbe/workflow.yaml',
chaosWkfCRDLink_Recur:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/sock-shop-demo/usingCmdProbe/workflow_cron.yaml',
gitLink:
'https://github.com/litmuschaos/chaos-charts/tree/master/workflows/sock-shop-demo',
chaosWkfCRDLink: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/sock-shop-demo/usingCmdProbe/workflow.yaml`,
chaosWkfCRDLink_Recur: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/sock-shop-demo/usingCmdProbe/workflow_cron.yaml`,
gitLink: `https://github.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/sock-shop-demo`,
provider: 'ChaosNative',
description: 'Induces chaos on Sock-Shop application',
totalRuns: 110,
Expand All @@ -31,12 +28,9 @@ export default [
title: 'kube-proxy-chaos',
chaosinfra: true,
urlToIcon: 'https://hub.litmuschaos.io/api/icon/1.8.0/generic/generic.png',
chaosWkfCRDLink:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/kube-proxy-all/workflow.yaml',
chaosWkfCRDLink_Recur:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/kube-proxy-all/workflow_cron.yaml',
gitLink:
'https://github.com/litmuschaos/chaos-charts/blob/master/workflows/kube-proxy-all',
chaosWkfCRDLink: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/kube-proxy-all/workflow.yaml`,
chaosWkfCRDLink_Recur: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/kube-proxy-all/workflow_cron.yaml`,
gitLink: `https://github.com/litmuschaos/chaos-charts/blob/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/kube-proxy-all`,
provider: 'MayaData',
description: 'Induces chaos on kube proxy',
totalRuns: 9000,
Expand All @@ -56,12 +50,9 @@ export default [
title: 'podtato-head-chaos',
chaosinfra: false,
urlToIcon: '/icons/podtato_head.png',
chaosWkfCRDLink:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/podtato-head/workflow.yaml',
chaosWkfCRDLink_Recur:
'https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/workflows/podtato-head/workflow_cron.yaml',
gitLink:
'https://github.com/litmuschaos/chaos-charts/tree/master/workflows/podtato-head',
chaosWkfCRDLink: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/podtato-head/workflow.yaml`,
chaosWkfCRDLink_Recur: `https://raw.githubusercontent.com/litmuschaos/chaos-charts/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/podtato-head/workflow_cron.yaml`,
gitLink: `https://github.com/litmuschaos/chaos-charts/tree/${process.env.REACT_APP_HUB_BRANCH_NAME}/workflows/podtato-head`,
provider: 'ChaosNative',
description: 'Induces chaos on podtato-head application',
totalRuns: 10,
Expand Down
15 changes: 8 additions & 7 deletions litmus-portal/frontend/src/utils/yamlUtils.ts
Expand Up @@ -47,13 +47,14 @@ export const updateEngineName = (parsedYaml: any) => {
// Edge Case: Condition to check the appns
// Required because while parsing the chaos engine
// '{{workflow.parameters.adminModeNamespace}}' changes to a JSON object
if (typeof chaosEngine.spec.appinfo.appns === 'object') {
// Removes any whitespace in '{{workflow.parameters.adminModeNamespace}}'
const appns = Object.keys(
chaosEngine.spec.appinfo.appns
)[0].replace(/\s/g, '');
chaosEngine.spec.appinfo.appns = `{${appns}}`;
}
if (chaosEngine.spec.appinfo)
if (typeof chaosEngine.spec.appinfo.appns === 'object') {
// Removes any whitespace in '{{workflow.parameters.adminModeNamespace}}'
const appns = Object.keys(
chaosEngine.spec.appinfo.appns
)[0].replace(/\s/g, '');
chaosEngine.spec.appinfo.appns = `{${appns}}`;
}
engineName += `${updatedEngineName} `;
}
// Update the artifact in template
Expand Down
2 changes: 0 additions & 2 deletions litmus-portal/graphql-server/pkg/authorization/middleware.go
Expand Up @@ -35,10 +35,8 @@ func RestMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
jwt := ""
auth, err := r.Cookie(CookieName)
fmt.Println("auth: ", auth)
if err == nil {
jwt = auth.Value
fmt.Println("jwt: ", jwt)
} else if r.Header.Get("Authorization") != "" {
jwt = r.Header.Get("Authorization")
}
Expand Down
16 changes: 16 additions & 0 deletions litmus-portal/graphql-server/pkg/myhub/ops/gitops.go
Expand Up @@ -92,6 +92,13 @@ func (c MyHubConfig) getChaosChartRepo() (string, error) {
URL: c.RepositoryURL, Progress: os.Stdout,
ReferenceName: plumbing.NewBranchReferenceName(c.Branch),
})
if err != nil {
_, err = git.PlainClone(ClonePath, false, &git.CloneOptions{
URL: c.RepositoryURL, Progress: os.Stdout,
ReferenceName: plumbing.NewTagReferenceName(c.Branch),
})
return c.Branch, err
}
return c.Branch, err
}

Expand All @@ -111,6 +118,15 @@ func (c MyHubConfig) getPrivateChaosChartRepo() (string, error) {
Progress: os.Stdout,
ReferenceName: plumbing.NewBranchReferenceName(c.Branch),
})
if err != nil {
_, err = git.PlainClone(ClonePath, false, &git.CloneOptions{
Auth: auth,
URL: c.RepositoryURL,
Progress: os.Stdout,
ReferenceName: plumbing.NewTagReferenceName(c.Branch),
})
return c.Branch, err
}
return c.Branch, err
}

Expand Down
2 changes: 1 addition & 1 deletion litmus-portal/graphql-server/pkg/project/create.go
Expand Up @@ -59,7 +59,7 @@ func CreateProjectWithUser(ctx context.Context, projectName string, userID strin
defaultHub := model.CreateMyHub{
HubName: "Chaos Hub",
RepoURL: "https://github.com/litmuschaos/chaos-charts",
RepoBranch: "master",
RepoBranch: os.Getenv("HUB_BRANCH_NAME"),
}

log.Print("Cloning https://github.com/litmuschaos/chaos-charts")
Expand Down
2 changes: 1 addition & 1 deletion litmus-portal/graphql-server/server.go
Expand Up @@ -29,7 +29,7 @@ func init() {
log.Printf("Go Version: %s", runtime.Version())
log.Printf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)

if os.Getenv("DB_SERVER") == "" || os.Getenv("JWT_SECRET") == "" || os.Getenv("SELF_CLUSTER") == "" || os.Getenv("AGENT_SCOPE") == "" || os.Getenv("AGENT_NAMESPACE") == "" || os.Getenv("LITMUS_PORTAL_NAMESPACE") == "" || os.Getenv("DB_USER") == "" || os.Getenv("DB_PASSWORD") == "" || os.Getenv("PORTAL_SCOPE") == "" || os.Getenv("SUBSCRIBER_IMAGE") == "" || os.Getenv("EVENT_TRACKER_IMAGE") == "" || os.Getenv("ARGO_SERVER_IMAGE") == "" || os.Getenv("ARGO_WORKFLOW_CONTROLLER_IMAGE") == "" || os.Getenv("ARGO_WORKFLOW_EXECUTOR_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_OPERATOR_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_RUNNER_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_EXPORTER_IMAGE") == "" || os.Getenv("CONTAINER_RUNTIME_EXECUTOR") == "" {
if os.Getenv("DB_SERVER") == "" || os.Getenv("JWT_SECRET") == "" || os.Getenv("SELF_CLUSTER") == "" || os.Getenv("AGENT_SCOPE") == "" || os.Getenv("AGENT_NAMESPACE") == "" || os.Getenv("LITMUS_PORTAL_NAMESPACE") == "" || os.Getenv("DB_USER") == "" || os.Getenv("DB_PASSWORD") == "" || os.Getenv("PORTAL_SCOPE") == "" || os.Getenv("SUBSCRIBER_IMAGE") == "" || os.Getenv("EVENT_TRACKER_IMAGE") == "" || os.Getenv("ARGO_SERVER_IMAGE") == "" || os.Getenv("ARGO_WORKFLOW_CONTROLLER_IMAGE") == "" || os.Getenv("ARGO_WORKFLOW_EXECUTOR_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_OPERATOR_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_RUNNER_IMAGE") == "" || os.Getenv("LITMUS_CHAOS_EXPORTER_IMAGE") == "" || os.Getenv("CONTAINER_RUNTIME_EXECUTOR") == "" || os.Getenv("HUB_BRANCH_NAME") == "" {
log.Fatal("Some environment variable are not setup")
}
}
Expand Down
2 changes: 2 additions & 0 deletions litmus-portal/namespaced-k8s-template.yml
Expand Up @@ -179,6 +179,8 @@ spec:
value: "litmuschaos/chaos-exporter:1.13.3"
- name: CONTAINER_RUNTIME_EXECUTOR
value: "k8sapi"
- name: HUB_BRANCH_NAME
value: "v1.13.x"
ports:
- containerPort: 8080
imagePullPolicy: Always
Expand Down
Expand Up @@ -171,6 +171,8 @@ spec:
value: "litmuschaos/chaos-exporter:1.13.3"
- name: CONTAINER_RUNTIME_EXECUTOR
value: "pns"
- name: HUB_BRANCH_NAME
value: "v1.13.x"
ports:
- containerPort: 8080
imagePullPolicy: Always
Expand Down
1 change: 1 addition & 0 deletions litmus-portal/run.sh
Expand Up @@ -22,6 +22,7 @@ export ADMIN_USERNAME=admin
export ADMIN_PASSWORD=litmus
export DB_USER=admin
export DB_PASSWORD=1234
export HUB_BRANCH_NAME=v1.13.x
# Dependency Checks
dir=($(pwd | tr "/" "\n"))
count=${#dir[@]}
Expand Down

0 comments on commit 7494b0b

Please sign in to comment.