Skip to content

Commit

Permalink
Namespace scope mode for litmus-portal and okteto cloud dev environme…
Browse files Browse the repository at this point in the history
…nt integration. (#2187)

This commit adds namespace scope installation configuration and required code changes for it to litmus-portal and also adds Okteto cloud dev environment setup.

Signed-off-by: ishangupta-ds <[email protected]>
  • Loading branch information
ishangupta-ds authored Oct 7, 2020
1 parent f2e28ce commit ce4bbab
Show file tree
Hide file tree
Showing 25 changed files with 2,565 additions and 176 deletions.
37 changes: 34 additions & 3 deletions litmus-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Litmus-Portal provides console and UI experience for managing, monitoring, and e
- Minikube
- GKE
- KIND
- EKS
- Okteto Cloud

## **Pre-requisites**

Expand All @@ -22,11 +24,41 @@ kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/v1.8.x/lit

Or

> Master (Latest)
> Master (Latest) Cluster scope. Installed in litmus namespace by default.
```bash
kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/k8s-manifest.yml
kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/cluster-k8s-manifest.yml
```

Or

> Master (Latest) Namespaced scope. Replace `<namespace>` with the desired namespace.
```bash
export LITMUS_PORTAL_NAMESPACE="<namespace>"
kubectl create ns ${LITMUS_PORTAL_NAMESPACE}
kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/litmus-portal-crds.yml
curl https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/namespaced-K8s-template.yml --output litmus-portal-namespaced-K8s-template.yml
envsubst < litmus-portal-namespaced-K8s-template.yml > ${LITMUS_PORTAL_NAMESPACE}-ns-scoped-litmus-portal-manifest.yml
kubectl apply -f ${LITMUS_PORTAL_NAMESPACE}-ns-scoped-litmus-portal-manifest.yml -n ${LITMUS_PORTAL_NAMESPACE}
kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/platforms/okteto/hello-world-AUT.yml -n ${LITMUS_PORTAL_NAMESPACE}
```

#### Configuration Options for Cluster scope.

- `litmus-portal-operations-config` configmap.

> `AgentNamespace: litmus`
- All environment variables.

#### Configuration Options for Namespace scope.

- `litmus-portal-operations-config` configmap.

> `AgentNamespace: ${LITMUS_PORTAL_NAMESPACE}`
- All environment variables.


#### Retrieving external url to access the litmus portal

```bash
Expand Down Expand Up @@ -63,7 +95,6 @@ kubectl delete -f https://raw.githubusercontent.com/litmuschaos/litmus/master/li
- GQLGEN GraphQL Server
- Database
- MongoDB
- Prometheus

##### **Additional information**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events

import (
"os"
"time"

"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
Expand All @@ -18,6 +19,11 @@ const (
resyncPeriod time.Duration = 0
)

var (
AgentScope = os.Getenv("AGENT_SCOPE")
AgentNamespace = os.Getenv("AGENT_NAMESPACE")
)

// initializes the Argo Workflow event watcher
func WorkflowEventWatcher(stopCh chan struct{}, stream chan types.WorkflowEvent) {
cfg, err := k8s.GetKubeConfig()
Expand All @@ -29,12 +35,18 @@ func WorkflowEventWatcher(stopCh chan struct{}, stream chan types.WorkflowEvent)
if err != nil {
logrus.WithError(err).Fatal("could not generate dynamic client for config")
}
// Create a factory object to watch workflows
f := externalversions.NewSharedInformerFactory(clientSet, resyncPeriod)
informer := f.Argoproj().V1alpha1().Workflows().Informer()

// Start Event Watch
go startWatch(stopCh, informer, stream)
// Create a factory object to watch workflows depending on default scope
if AgentScope == "namespace" {
f := externalversions.NewSharedInformerFactoryWithOptions(clientSet, resyncPeriod, externalversions.WithNamespace(AgentNamespace))
informer := f.Argoproj().V1alpha1().Workflows().Informer()
// Start Event Watch
go startWatch(stopCh, informer, stream)
} else {
f := externalversions.NewSharedInformerFactory(clientSet, resyncPeriod)
informer := f.Argoproj().V1alpha1().Workflows().Informer()
// Start Event Watch
go startWatch(stopCh, informer, stream)
}
}

// handles the different workflow events - add, update and delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func ClusterConnect(clusterData map[string]string) {
query := `{"query":"subscription {\n clusterConnect(clusterInfo: {cluster_id: \"` + clusterData["CID"] + `\", access_key: \"` + clusterData["KEY"] + `\"}) {\n \t project_id,\n action{\n k8s_manifest,\n external_data,\n request_type\n }\n }\n}\n"}`
query := `{"query":"subscription {\n clusterConnect(clusterInfo: {cluster_id: \"` + clusterData["CID"] + `\", access_key: \"` + clusterData["KEY"] + `\"}) {\n \t project_id,\n action{\n k8s_manifest,\n external_data,\n request_type\n namespace\n }\n }\n}\n"}`
serverURL, err := url.Parse(clusterData["GQL_SERVER"])
scheme := "ws"
if serverURL.Scheme == "https" {
Expand Down Expand Up @@ -87,7 +87,7 @@ func ClusterConnect(clusterData map[string]string) {
SendPodLogs(clusterData, podRequest)
} else if strings.Index("create update delete get", strings.ToLower(r.Payload.Data.ClusterConnect.Action.RequestType)) >= 0 {
logrus.Print("WORKFLOW REQUEST ", r.Payload.Data.ClusterConnect.Action)
_, err = k8s.ClusterOperations(r.Payload.Data.ClusterConnect.Action.K8SManifest, r.Payload.Data.ClusterConnect.Action.RequestType)
_, err = k8s.ClusterOperations(r.Payload.Data.ClusterConnect.Action.K8SManifest, r.Payload.Data.ClusterConnect.Action.RequestType, r.Payload.Data.ClusterConnect.Action.Namespace)
if err != nil {
logrus.WithError(err).Print("error performing cluster operation")
continue
Expand Down
11 changes: 6 additions & 5 deletions litmus-portal/cluster-agents/subscriber/pkg/k8s/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"

yaml_converter "github.com/ghodss/yaml"
corev1 "k8s.io/api/core/v1"
Expand All @@ -20,13 +21,13 @@ import (

const (
PortalConfigName = "litmus-portal-config"
DefaultNamespace = "litmus"
)

var (
Ctx = context.Background()
decUnstructured = yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
dr dynamic.ResourceInterface
AgentNamespace = os.Getenv("AGENT_NAMESPACE")
)

// IsClusterConfirmed checks if the config map with "is_cluster_confirmed" is true or not.
Expand All @@ -36,7 +37,7 @@ func IsClusterConfirmed(clusterData map[string]string) (bool, string, error) {
return false, "", err
}

getCM, err := clientset.CoreV1().ConfigMaps(DefaultNamespace).Get(PortalConfigName, metav1.GetOptions{})
getCM, err := clientset.CoreV1().ConfigMaps(AgentNamespace).Get(PortalConfigName, metav1.GetOptions{})
if errors.IsNotFound(err) {
return false, "", nil
} else if getCM.Data["is_cluster_confirmed"] == "true" {
Expand Down Expand Up @@ -72,7 +73,7 @@ func ClusterRegister(clusterData map[string]string) (bool, error) {
Data: configMapData,
}

_, err = clientset.CoreV1().ConfigMaps(DefaultNamespace).Create(&newConfigMap)
_, err = clientset.CoreV1().ConfigMaps(AgentNamespace).Create(&newConfigMap)
if err != nil {
return false, nil
}
Expand Down Expand Up @@ -138,7 +139,7 @@ func applyRequest(requestType string, obj *unstructured.Unstructured) (*unstruct
}

// This function handles cluster operations
func ClusterOperations(manifest string, requestType string) (*unstructured.Unstructured, error) {
func ClusterOperations(manifest string, requestType string, namespace string) (*unstructured.Unstructured, error) {

// Converting JSON to YAML and store it in yamlStr variable
yamlStr, err := yaml_converter.JSONToYAML([]byte(manifest))
Expand Down Expand Up @@ -171,7 +172,7 @@ func ClusterOperations(manifest string, requestType string) (*unstructured.Unstr
// Obtain REST interface for the GVR
if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
// namespaced resources should specify the namespace
dr = dynamicClient.Resource(mapping.Resource).Namespace("litmus")
dr = dynamicClient.Resource(mapping.Resource).Namespace(namespace)
} else {
// for cluster-wide resources
dr = dynamicClient.Resource(mapping.Resource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ type Action struct {
K8SManifest string `json:"k8s_manifest"`
ExternalData interface{} `json:"external_data"`
RequestType string `json:"request_type"`
Namespace string `json:"namespace"`
}
Loading

0 comments on commit ce4bbab

Please sign in to comment.