-
Notifications
You must be signed in to change notification settings - Fork 772
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
support updating template store #607
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1af2aa3
feature: updates - Added the subcommand which accepts one argument an…
Abiji-2020 96b15c1
Merge branch 'cyclops-ui:main' into template-store
Abiji-2020 9c72bac
fix: updated the suggested modfications from the review
Abiji-2020 2d59be0
Merge branch 'cyclops-ui:main' into template-store
Abiji-2020 80ed299
Update cyctl/internal/update/template_store.go
Abiji-2020 48d1d17
fix: updated the new line after the success message
Abiji-2020 34dba95
Update cyctl/internal/update/template_store.go
Abiji-2020 8e50fc8
updated the template store to support the command updates [alias]
Abiji-2020 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package update | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" | ||
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" | ||
"github.com/spf13/cobra" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var ( | ||
updateTemplateStoreExample = `# updates template store | ||
|
||
# Update template sample command | ||
cyctl update template NAME --repo='https://github.com/cyclops-ui/templates' --path='/path' --version='main' --icon='icon'` | ||
) | ||
|
||
var ( | ||
repo string | ||
path string | ||
icon string | ||
version string | ||
) | ||
|
||
// updates he given template from cyclops API | ||
func updateTemplate(clientset *client.CyclopsV1Alpha1Client, templateName, path, version, repo, icon string) { | ||
// Fetch the existing template store | ||
template, err := clientset.TemplateStore("cyclops").Get(templateName) | ||
if err != nil { | ||
log.Fatal("Failed to fetch template store:", err.Error()) | ||
return | ||
} | ||
|
||
// Update the template store fields if provided | ||
if repo != "" { | ||
template.Spec.URL = repo | ||
} | ||
if path != "" { | ||
template.Spec.Path = path | ||
} | ||
if version != "" { | ||
template.Spec.Version = version | ||
} | ||
if icon != "" { | ||
if template.ObjectMeta.Annotations == nil { | ||
template.ObjectMeta.Annotations = make(map[string]string) | ||
} | ||
template.ObjectMeta.Annotations["cyclops-ui.com/icon"] = icon | ||
} | ||
template.TypeMeta = v1.TypeMeta{ | ||
APIVersion: "cyclops-ui.com/v1alpha1", | ||
Kind: "TemplateStore", | ||
} | ||
|
||
// Update the template store in the cluster | ||
_, err = clientset.TemplateStore("cyclops").Update(template) | ||
if err != nil { | ||
fmt.Println("Failed to update template store ", err) | ||
return | ||
} | ||
|
||
fmt.Printf("successfully updated %v \n", templateName) | ||
|
||
} | ||
|
||
var ( | ||
UpdateTemplateStoreCMD = &cobra.Command{ | ||
Use: "template", | ||
Short: "updates template values; takes template name as argument and updates values provided by flags", | ||
Long: "updates template values; takes template name as argument with flags --path=<path> --repo=<repo> --version=<version> --icon=<icon> ", | ||
Example: updateTemplateStoreExample, | ||
Aliases: []string{"templates"}, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
templateName := args[0] | ||
|
||
if repo == "" && path == "" && version == "" && icon == "" { | ||
log.Fatal("Error: At least on of --repo, --path, --version, or --icon must be provided.") | ||
} | ||
|
||
updateTemplate(kubeconfig.Moduleset, templateName, path, version, repo, icon) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
UpdateTemplateStoreCMD.Flags().StringVar(&repo, "repo", "", "Repository URL of the template store") | ||
UpdateTemplateStoreCMD.Flags().StringVar(&path, "path", "", "Path to the charts in the repository") | ||
UpdateTemplateStoreCMD.Flags().StringVar(&version, "version", "", "Version of the template store") | ||
UpdateTemplateStoreCMD.Flags().StringVar(&icon, "icon", "", "Icon for the template store (stored in metadata.annotations.cyclops-ui.com/icon)") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add alias here:
#607 (comment)