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

cyclops cli: support for update command #475

Merged
merged 21 commits into from
Jul 29, 2024

Conversation

ashish111333
Copy link
Contributor

@ashish111333 ashish111333 commented Jul 28, 2024

closes #454

πŸ“‘ Description

adds support for the updating modules using cyctl cli

βœ… Checks

  • I have updated the documentation as required
  • I have performed a self-review of my code

Additional context

cyclops cli currently supports create,delete,describe,get ,this PR adds support for update

@ashish111333 ashish111333 requested a review from a team as a code owner July 28, 2024 20:03
@ashish111333 ashish111333 changed the title support for update command cyclops cli: support for update command Jul 29, 2024
Copy link
Collaborator

@petar-cvit petar-cvit left a comment

Choose a reason for hiding this comment

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

Thanks @ashish111333, left two comments

cyctl/internal/update/modules.go Outdated Show resolved Hide resolved

// updates the given module from cyclops API
// currently supports updating replica count for a module
func updateModule(clientset *client.CyclopsV1Alpha1Client, moduleName, key string, value int) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make the value type interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ashish111333
Copy link
Contributor Author

have done the requested changes,can you review it now @petar-cvit

Copy link
Collaborator

@petar-cvit petar-cvit left a comment

Choose a reason for hiding this comment

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

Thanks @ashish111333, left a couple of comments

return

}
SpecValuesMap := make(map[string]interface{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to specValuesMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return

}
err = unstructured.SetNestedField(SpecValuesMap, value, key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you have a key that is nested (like scaling.replicas) you will have to split the keys by dots

Suggested change
err = unstructured.SetNestedField(SpecValuesMap, value, key)
err = unstructured.SetNestedField(SpecValuesMap, value, strings.Split(key, ".")...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

fmt.Println("failed to encode to json: ", err)
return
}
module.Spec.Values = apiextensionv1.JSON{Raw: updatedSpecValues}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You will also have to populate typeMeta before updating

Suggested change
module.Spec.Values = apiextensionv1.JSON{Raw: updatedSpecValues}
module.Spec.Values = apiextensionv1.JSON{Raw: updatedSpecValues}
module.TypeMeta = v1.TypeMeta{
APIVersion: "cyclops-ui.com/v1alpha1",
Kind: "Module",
}

fmt.Println("failed to update module: ", err)
return
}
fmt.Printf("successfully updated %v", updatedModule.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use moduleName without getting it from the updatedModule

Suggested change
fmt.Printf("successfully updated %v", updatedModule.Name)
fmt.Printf("successfully updated %v", moduleName)

minor fixes
Copy link
Collaborator

@petar-cvit petar-cvit left a comment

Choose a reason for hiding this comment

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

@ashish111333 Build is failing because you need to unpack split output using strings.Split(key, ".").... Also, remove unused updatedModule variable

}

var (
UpdateModule = &cobra.Command{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the name to updateModuleCMD. Update command name in init func as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah

Copy link
Collaborator

@petar-cvit petar-cvit left a comment

Choose a reason for hiding this comment

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

Thanks @ashish111333 🧑

@petar-cvit petar-cvit merged commit e095bce into cyclops-ui:main Jul 29, 2024
1 check passed
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.

support updating modules using cyctl
2 participants