-
Notifications
You must be signed in to change notification settings - Fork 693
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
[litmus-portal]Updating to use kubernetes patch instead of get-update in subscriber for updating cm and secret #3981
Conversation
Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. Gave few comments, PTAL
@@ -158,52 +160,42 @@ func IsClusterConfirmed() (bool, string, error) { | |||
|
|||
// ClusterRegister function creates litmus-portal config map in the litmus namespace | |||
func ClusterRegister(clusterData map[string]string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to patch two things
- IS_CLUSTER_CONFIRMED
- ACCESS_KEY
so, the func params can be be the access_key only and is_cluster_confirmed is a boolean(no need to add it in params)
func ClusterRegister(clusterData map[string]string) (bool, error) { | |
func ClusterRegister(accessKey string) (bool, error) { |
"SKIP_SSL_VERIFY": clusterData["SKIP_SSL_VERIFY"], | ||
"CUSTOM_TLS_CERT": clusterData["CUSTOM_TLS_CERT"], | ||
configMapPatch:= map[string]interface{}{ | ||
"data": clusterData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only need to patch IS_CLUSTER_CONFIRMED as mentioned above
"ACCESS_KEY": clusterData["ACCESS_KEY"], | ||
"CLUSTER_ID": clusterData["CLUSTER_ID"], | ||
secretPatch:= map[string]interface{}{ | ||
"stringData":clusterData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to patch ACCESS_KEY only
|
||
logrus.Info(AgentSecretName + " has been updated") | ||
logrus.Info(AgentSecretName+" has been updated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.Info(AgentSecretName+" has been updated") | |
logrus.Infof("%s has been patched", AgentSecretName) |
if err != nil { | ||
return false, err | ||
} | ||
|
||
logrus.Info(AgentConfigName + " has been updated") | ||
logrus.Info(AgentConfigName+" has been updated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.Info(AgentConfigName+" has been updated") | |
logrus.Infof("%s has been patched", AgentConfigName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I will makes these changes and update the PR
…iber/pkg/k8s/operations.go Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
…agents/subscriber/pkg/k8s/operations.go Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
@imrajdas I have updated the code and updated the pr . Can the maintainers have a look at it |
@@ -157,53 +159,48 @@ func IsClusterConfirmed() (bool, string, error) { | |||
} | |||
|
|||
// ClusterRegister function creates litmus-portal config map in the litmus namespace | |||
func ClusterRegister(clusterData map[string]string) (bool, error) { | |||
clientset, err := GetGenericK8sClient() | |||
func ClusterRegister(accessKey string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check where ClusterRegister() is being called and update the params there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at how patch works and whats the expected inputs for it and test the code locally to make sure it works.
isClusterConfirmed, _, err := IsClusterConfirmed() | ||
if err != nil { | ||
return false, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call it again, pass it as param as suggested by raj.
}, | ||
}, metav1.UpdateOptions{}) | ||
configMapPatch:= map[string]bool { | ||
"data": isClusterConfirmed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test if this works? You need to specify the key-value mapping for the patch, here you just put the bool value directly under data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achiverram28 You can try something like this
updatedConfigMap := corev1.ConfigMap{
Data: map[string]string{
"<key>": "<value>",
},
}
configMapPatch, err := json.Marshal(updatedConfigMap)
if err != nil {
return fmt.Errorf("failed to marshal patched config, err: %v", err)
}
logrus.Info("%s has been patched",AgentConfigName) | ||
|
||
secretPatch:= map[string]string{ | ||
"stringData": accessKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here need to specify the map
"VERSION": clusterData["VERSION"], | ||
"SKIP_SSL_VERIFY": clusterData["SKIP_SSL_VERIFY"], | ||
"CUSTOM_TLS_CERT": clusterData["CUSTOM_TLS_CERT"], | ||
isClusterConfirmed, _, err := IsClusterConfirmed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by Shomo, this function is not needed here. Instead, you can directly set the value to true
since we are already updating the map here:
clusterData["IS_CLUSTER_CONFIRMED"] = "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the requested changes @achiverram28
Yes , I will work on all of these changes and update the pr . Thanks for the guidance |
…s.go and litmus-portal/cluster-agents/subscriber/subscriber.go Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
I have made changes by updating the params of the Sir , what shall we do about the |
Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
The litmus-portal directory is a legacy directory (will be depreciated soon), and the latest code base derives its logic from the chaos-centre directory, can you please make your changes there. |
Proposed changes
The ClusterRegister function in the litmus/litmus-portal/cluster-agents/subscriber/pkg/k8s
/operations.go has been modified to use kubernetes patch instead of update in subscriber for updating cm and secret
This solves the issue #3944
I have made use of the json.Marshal for the clusterData and have used it in Patch(MergePatchType) for both configMap and Secret patch.
Types of changes
What types of changes does your code introduce to Litmus? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.