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

[litmus-portal]Updating to use kubernetes patch instead of get-update in subscriber for updating cm and secret #3981

Closed
wants to merge 5 commits into from

Conversation

achiverram28
Copy link

@achiverram28 achiverram28 commented May 19, 2023

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 apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

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.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
Copy link
Member

@imrajdas imrajdas left a 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) {
Copy link
Member

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

  1. IS_CLUSTER_CONFIRMED
  2. 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)

Suggested change
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,
Copy link
Member

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,
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logrus.Info(AgentConfigName+" has been updated")
logrus.Infof("%s has been patched", AgentConfigName)

Copy link
Author

@achiverram28 achiverram28 May 20, 2023

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

@imrajdas
Copy link
Member

cc: @gdsoumya @amityt for reviews

@imrajdas imrajdas requested review from amityt and gdsoumya May 20, 2023 14:44
…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>
@achiverram28
Copy link
Author

@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) {
Copy link
Member

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

Copy link
Member

@gdsoumya gdsoumya left a 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.

Comment on lines 168 to 170
isClusterConfirmed, _, err := IsClusterConfirmed()
if err != nil {
return false, err
Copy link
Member

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,
Copy link
Member

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

Copy link
Contributor

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,
Copy link
Member

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()
Copy link
Contributor

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"

Copy link
Contributor

@amityt amityt left a 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

@achiverram28
Copy link
Author

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>
@achiverram28
Copy link
Author

achiverram28 commented May 21, 2023

I have made changes by updating the params of the ClusterRegister() in subscriber.go @imrajdas .
I have removed the function call inside and studied the subscriber.go and passed it as a parameter to ClusterRegister() . So I have passed accessKey and isClusterConfirmed as arguments in subscriber.go @imrajdas @gdsoumya @amityt .
Sorry for the mistake during ConfigMap and Secret creation . As per the guidance of @amityt and @gdsoumya I properly studied this usage and input for those and modified by adding maps .
Hope this solves all the requested changes . If any more changes I am open for it.

Sir , what shall we do about the AgentNamespace since it was commented , in the original code , how should we deal with that . This one

Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
@vanshBhatia-A4k9
Copy link
Member

vanshBhatia-A4k9 commented Dec 8, 2023

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.
Example: make changes in chaoscenter/subscriber/pkg/k8s/operations.go instead of litmus-portal/cluster-agents/subscriber/pkg/k8s/operations.go. cc: @Saranya-jena

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants