Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workflow configmap model #591

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions custom/litmus-helm-agent/pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"os"

corev1r "k8s.io/api/core/v1"

"encoding/json"
metav1r "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -28,20 +29,18 @@ func ConnectKubeApi() *kubernetes.Clientset {
return clientset
}

func CreateConfigMap(configmapName string, configMapData map[string]string, NAMESPACE string, clientset *kubernetes.Clientset) {
configMap := corev1r.ConfigMap{
TypeMeta: metav1r.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1r.ObjectMeta{
Name: configmapName,
Namespace: NAMESPACE,
},
Data: configMapData,
func PatchConfigMap(configmapName string, configMapData map[string]string, NAMESPACE string, clientset *kubernetes.Clientset) {
jsonStr, err := json.Marshal(configMapData)
if err != nil {
fmt.Printf("❌ Error when converting " + configmapName + " data to json: " + err.Error() + "\n")
os.Exit(1)
}
patchPayload := `
{
"data": ` + string(jsonStr) + `
}`

_, err := clientset.CoreV1().ConfigMaps(NAMESPACE).Update(context.TODO(), &configMap, metav1r.UpdateOptions{})
_, err = clientset.CoreV1().ConfigMaps(NAMESPACE).Patch(context.TODO(), configmapName, types.StrategicMergePatchType, []byte(patchPayload), metav1r.PatchOptions{})
if err != nil {
fmt.Printf("❌ Cannot update configmap " + configmapName + " : " + err.Error() + "\n")
os.Exit(1)
Expand Down
13 changes: 6 additions & 7 deletions custom/litmus-helm-agent/pkg/litmus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ func prepareInfraSecret(infraConnect infrastructure.RegisterInfra, accessKey str

func prepareWorkflowControllerConfigMap(clusterID string) map[string]string {
configMapWorkflowController := make(map[string]string)
configMapWorkflowController["config"] = (` containerRuntimeExecutor: ` + os.Getenv("CONTAINER_RUNTIME_EXECUTOR") + `
executor:
imagePullPolicy: IfNotPresent
instanceID: ` + clusterID)
return configMapWorkflowController

configMapWorkflowController["containerRuntimeExecutor"] = os.Getenv("CONTAINER_RUNTIME_EXECUTOR")
configMapWorkflowController["instanceID"] = clusterID

return configMapWorkflowController
}

func GetProjectID(credentials types.Credentials) string {
Expand Down Expand Up @@ -148,13 +147,13 @@ func CreateInfra(credentials types.Credentials) {

clientset := kubernetes.ConnectKubeApi()
configMap := prepareInfraConfigMap()
kubernetes.CreateConfigMap(os.Getenv("INFRA_CONFIGMAP_NAME"), configMap, os.Getenv("NAMESPACE"), clientset)
kubernetes.PatchConfigMap(os.Getenv("INFRA_CONFIGMAP_NAME"), configMap, os.Getenv("NAMESPACE"), clientset)

secret := prepareInfraSecret(connectionData.Data, accessKey)
kubernetes.CreateSecret(os.Getenv("INFRA_SECRET_NAME"), secret, os.Getenv("NAMESPACE"), clientset)

workflowConfigMap := prepareWorkflowControllerConfigMap(connectionData.Data.RegisterInfraDetails.InfraID)
kubernetes.CreateConfigMap(os.Getenv("WORKFLOW_CONTROLER_CONFIGMAP_NAME"), workflowConfigMap, os.Getenv("NAMESPACE"), clientset)
kubernetes.PatchConfigMap(os.Getenv("WORKFLOW_CONTROLER_CONFIGMAP_NAME"), workflowConfigMap, os.Getenv("NAMESPACE"), clientset)

fmt.Printf("Infra Successfully declared, starting...\n")
} else {
Expand Down
Loading