-
Notifications
You must be signed in to change notification settings - Fork 14
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
Cluster overrides functionality in gen2 clusters #364
Cluster overrides functionality in gen2 clusters #364
Conversation
da1f438
to
ffdc923
Compare
cmd/cluster/cluster.go
Outdated
@@ -17,7 +10,7 @@ func NewCommand() *cobra.Command { | |||
Short: "Manage clusters", | |||
Long: "Manage clusters", | |||
DisableAutoGenTag: true, | |||
PersistentPreRun: checkForArgocd, | |||
//PersistentPreRun: checkForArgocd, |
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.
delete
cmd/cluster/cluster.go
Outdated
os.Exit(1) | ||
} | ||
} | ||
// func checkForArgocd(c *cobra.Command, args []string) { |
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.
delete if unused
cmd/cluster/create.go
Outdated
@@ -55,6 +63,19 @@ func createClusterCommand() *cobra.Command { | |||
if err != nil { | |||
return fmt.Errorf("failed to get repository credentials: %s", err) | |||
} | |||
overRiden := false |
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.
Spelling is incorrect. Rename to overridden
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.
I corrected the spelling everywhere in the code now.
cmd/cluster/create.go
Outdated
var clusterRepoPath string | ||
var clusterName string | ||
var overRides string |
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.
Naming is weird. Rename to overrides
.
cmd/cluster/create.go
Outdated
@@ -55,6 +63,19 @@ func createClusterCommand() *cobra.Command { | |||
if err != nil { | |||
return fmt.Errorf("failed to get repository credentials: %s", err) | |||
} | |||
overRiden := false | |||
if overRides != " " { |
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.
This looks wrong. There's a space between the quotes.
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.
removed the space between quotes
pkg/gitutils/gitutils.go
Outdated
@@ -58,3 +59,29 @@ func CommitChanges(tmpDir string, wt *gogit.Worktree, commitMsg string) (changed | |||
} | |||
return | |||
} | |||
|
|||
func CommitDeletechanges(tmpDir string, wt *gogit.Worktree, commitMsg string) (changed bool, err 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.
- Rename:
CommitDeleteChanges
- How is this different from CommitChanges()? If the differences are none or minimal, consider consolidating into one function.
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.
CommitChanges() function doesn't find the files which have been deleted and hence, it shows that there is nothing to commit even if few files have been deleted. Whereas the CommitDeleteChanges() finds the files which have been deleted and add and commit them.
pkg/gitutils/manifests.go
Outdated
return fmt.Errorf("failed to open embedded file %s: %s", filePath, err) | ||
} | ||
|
||
kustomfile, err := ioutil.ReadFile(newFilePath) |
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.
Suggested naming: kustomFile
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.
Yes, I renamed all the other variables as well
pkg/gitutils/manifests.go
Outdated
var targetcomp []string | ||
var kind string | ||
var information info | ||
for kustomkey, kustomval := range parsedData { |
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.
Suggested naming: kustomKey, kustomVal. Same thing for others like targetcomp and strkustomval.
pkg/cluster/cluster_app.go
Outdated
) (*argoappv1.Application, error) { | ||
app := constructClusterApp(argocdNs, clusterName, baseClusterName, | ||
repoUrl, repoRevision, repoPath) | ||
repoUrl, repoRevision, repoPath, overRiden) |
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.
Rename to overridden
pkg/cluster/cluster_app.go
Outdated
) *argoappv1.Application { | ||
clusterOverridden := "false" |
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.
This is cleaner: clusterOverridden := fmt.Sprintf("%v", overridden)
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.
The functionality that copies / transforms the patch files from the patch directory to the destination git directory is a good candidate for a unit test. See if you can add a unit test for it.
pkg/cluster/delete.go
Outdated
@@ -126,3 +90,57 @@ func Delete( | |||
} | |||
return nil | |||
} | |||
|
|||
func DeleteOverrideDir(appIf argoapp.ApplicationServiceClient, kubeClient *kubernetes.Clientset, argocdNs string, name string) 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.
A few nits:
- Rename the function to
DeleteOverridesDir()
- Rename
name
toclusterName
since it's not clear what thing we're talking about.
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.
Renamed both the fields
pkg/cluster/delete.go
Outdated
if err != nil { | ||
return fmt.Errorf("failed to push to remote repository: %s", err) | ||
return fmt.Errorf("failed to delete the override directory: %s", 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.
"overrides directory"
pkg/cluster/delete.go
Outdated
clusterQuery := "arlon-cluster=" + name | ||
apps, err := appIf.List(context.Background(), | ||
&argoapp.ApplicationQuery{Selector: &clusterQuery}) | ||
if err != nil { | ||
return fmt.Errorf("failed to list apps related to cluster: %s", err) | ||
} | ||
|
||
app, err := appIf.Get(context.Background(), |
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.
It's unnecessary to get the "cluster-app" app here, because line 53 already gets all apps related to this cluster, and lines 77-92 iterate over those apps. So you should insert code in that loop to catch the one of type cluster-app, and then handle it.
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.
removed the unnecessary calling of appIf.List again and used the loop in lines 77-92 to do the same
pkg/cluster/delete.go
Outdated
|
||
func DeleteOverrideDir(appIf argoapp.ApplicationServiceClient, kubeClient *kubernetes.Clientset, argocdNs string, name string) error { | ||
log := logpkg.GetLogger() | ||
app, err := appIf.Get(context.Background(), |
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.
This function should not need to get the app again. The caller already has a copy of the app. Pass it by pointer.
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.
Passed the app pointer instead of appIf
pkg/cluster/delete.go
Outdated
return fmt.Errorf("failed to get argocd application: %s", err) | ||
} | ||
typ := app.Labels["arlon-type"] | ||
if typ == "cluster-app" { |
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.
There's no need to check the type if we assume the caller has already done so. You can:
- Not check
- Still check, and return an error if it's not of the expected type.
pkg/cluster/types.go
Outdated
@@ -15,6 +15,7 @@ type BaseClusterInfo struct { | |||
RepoUrl string | |||
RepoRevision string | |||
RepoPath string | |||
OverRidden string |
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.
Rename to overridden
pkg/gitutils/manifests.go
Outdated
src, err := os.OpenFile(newFilePath, os.O_RDONLY, os.ModePerm) | ||
if err != nil { | ||
_ = src.Close() | ||
return fmt.Errorf("failed to open embedded file %s: %s", filePath, 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.
Why does this say embedded
? Should it say patch file
instead?
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.
renamed it to patch file
pkg/gitutils/manifests.go
Outdated
kustomFile, err := ioutil.ReadFile(newFilePath) | ||
if err != nil { | ||
_ = src.Close() | ||
return fmt.Errorf("Failed to read the embedded file %s", 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.
Same comment about "embedded" terminology.
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.
Some missing error checks.
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.
One more minor code change.
pkg/cluster/delete.go
Outdated
} | ||
wt, err := repo.Worktree() | ||
fileInfo, err := wt.Filesystem.Lstat(repoPath) | ||
if err == nil { |
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.
It's more elegant to check for err != nil and return early (see line 112). This way, lines 104-110 can be re-indented and aligned with the rest of the function body.
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.
Yes, I'm checking for err!=nil case first now
* Added overrides support for gen2 clusters * refactored the code to make the override feature work on existing bc design * Added a check if the cluster already exists before creating patch file * Added documentation for clusteroverides design proposal * Added override in user facing docs(gen2_Tutorial.md) * Addressed all the reviews(Cleared confusion in patch revision and patch repo path) * Edited the desc for patchreporevision * Addressed the reviews(Code refactoring) * Removed unnecessary code * renamed overriden * Handled the errors in delete function * Refactored the code Co-authored-by: Jayanth Reddy <[email protected]>
Fixes #111
This PR adds cluster overrides functionality to gen2 clusters. A user can now generate a cluster with changes from a single base manifest without the need to change the original manifest. The design doc of the overrides: overrides-doc
The cluster which are deployed using patches( with --override flag) are turning out to be healthy as well.