-
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
Resolved the issue where patch file can't point to a resource based on a name #385
Resolved the issue where patch file can't point to a resource based on a name #385
Conversation
Codecov Report
@@ Coverage Diff @@
## main #385 +/- ##
==========================================
+ Coverage 28.71% 29.33% +0.62%
==========================================
Files 25 25
Lines 1654 1619 -35
==========================================
Hits 475 475
+ Misses 1132 1097 -35
Partials 47 47
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
docs/gen2_Tutorial.md
Outdated
@@ -375,24 +375,35 @@ arlon cluster create --cluster-name <clusterName> --repo-alias prod --repo-path | |||
|
|||
We call the concept of constructing various clusters with patches from the same base manifest as cluster overrides. | |||
The cluster overrides feature is built on top of the existing base cluster design. So, A user can create a cluster from the base manifest using the same command as in the above step(gen2 cluster creation). | |||
Now, to create a cluster with overrides in the base manifest, a user should have the corresponding patch files in a dedicated folder in local which doesn't contain any other files except patch files. Example of a patch file where we want to override replicas count to 2 is: | |||
Now, to create a cluster with overrides in the base manifest, a user should have the corresponding patch files in a single yaml file in local. Example of a patch file where we want to override replicas count to 2 is and change the sshkeyname: |
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.
Now, to create a cluster with overrides in the base manifest, a user should have the corresponding patch files in a single yaml file in local. Example of a patch file where we want to override replicas count to 2 is and change the sshkeyname: | |
Now, to create a cluster with overrides in the base manifest, a user should have the corresponding patch files in a single yaml file in local. Here is an example of a patch file where we want to override replicas count to 2 and change the sshkeyname: |
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.
Made a couple of suggestions.
docs/gen2_Tutorial.md
Outdated
Refer to this [document](https://blog.scottlowe.org/2019/11/12/using-kustomize-with-cluster-api-manifests/) to know more about patch files | ||
|
||
Command to create a gen2 workload cluster form the base cluster manifest with overrides to the manifest is: | ||
|
||
```shell | ||
arlon cluster create <cluster-name> --repo-url <repo url where base manifest is present> --repo-path <repo path to the base manifest> --override <path to the patch files folder> --patch-repo-url <repo url where patch files should be stored> --patch-repo-path <repo path to store the patch files> | ||
arlon cluster create <cluster-name> --repo-url <repo url where base manifest is present> --repo-path <repo path to the base manifest> --overrides-path <path to the patch files folder> --patch-repo-url <repo url where patch files should be stored> --patch-repo-path <repo path to store the patch files> |
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.
arlon cluster create <cluster-name> --repo-url <repo url where base manifest is present> --repo-path <repo path to the base manifest> --overrides-path <path to the patch files folder> --patch-repo-url <repo url where patch files should be stored> --patch-repo-path <repo path to store the patch files> | |
arlon cluster create <cluster-name> --repo-url <repo url where base manifest is present> --repo-path <repo path to the base manifest> --overrides-path <path to the patch file> --patch-repo-url <repo url where patch file should be stored> --patch-repo-path <repo path to store the patch file> |
pkg/gitutils/manifests.go
Outdated
@@ -168,9 +104,25 @@ func CopyPatchManifests(wt *gogit.Worktree, filePath string, clusterPath string, | |||
return fmt.Errorf("failed to create kustomization.yaml: %s", err) | |||
} | |||
err = tmpl.Execute(file, yamlData) | |||
if err != nil { | |||
return fmt.Errorf("failed to execute kustomization.yaml manifest: %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.
return fmt.Errorf("failed to execute kustomization.yaml manifest: %s", err) | |
return fmt.Errorf("failed to execute kustomization.yaml manifest") |
74ac6ee
to
e5c8cc5
Compare
pkg/gitutils/manifests.go
Outdated
@@ -168,9 +104,25 @@ func CopyPatchManifests(wt *gogit.Worktree, filePath string, clusterPath string, | |||
return fmt.Errorf("failed to create kustomization.yaml: %s", err) | |||
} | |||
err = tmpl.Execute(file, yamlData) | |||
if err != nil { | |||
return fmt.Errorf("failed to execute kustomization.yaml manifest") | |||
} | |||
_ = file.Close() |
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.
Move this to above 106 with a defer
pkg/gitutils/manifests.go
Outdated
return fmt.Errorf("failed to create destination file %s: %s", dstPath, err) | ||
} | ||
_, err = io.Copy(dst, src) | ||
_ = src.Close() |
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.
Not needed if deferred above.
pkg/gitutils/manifests.go
Outdated
dstPath := path.Join(clusterPath, fileName) | ||
dst, err := wt.Filesystem.Create(dstPath) | ||
if err != nil { | ||
_ = src.Close() |
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.
Not needed if deferred above.
pkg/gitutils/manifests.go
Outdated
} | ||
_, err = io.Copy(dst, src) | ||
_ = src.Close() | ||
_ = dst.Close() |
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.
Move to before 120 with defer
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 fix the minor nit before merging. Approved.
@@ -167,10 +104,24 @@ func CopyPatchManifests(wt *gogit.Worktree, filePath string, clusterPath string, | |||
if err != nil { | |||
return fmt.Errorf("failed to create kustomization.yaml: %s", err) | |||
} | |||
defer file.Close() |
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.
General comment:
Can you change the defers to: defer _ = xxx.Close()
or else my IDE will complain about the return value not being used. Not sure what IDE you use.
In the present overrides design, a user can't point to a single resource in resources file using the name of resource. The patch gets applied to all the resources irrespective of the name field in patch.yaml. This PR fixes this issue and now, user can apply a patch to a particular resource using the name field in patch.yaml. Deployed a cluster from the branch and it turned out to be healthy and synced with the patch changes.