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

Resolved the issue where patch file can't point to a resource based on a name #385

Merged
merged 5 commits into from
Dec 20, 2022

Conversation

jayanth-tjvrr
Copy link
Member

@jayanth-tjvrr jayanth-tjvrr commented Dec 20, 2022

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.
image

@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 03:32 — with GitHub Actions Inactive
@jayanth-tjvrr jayanth-tjvrr self-assigned this Dec 20, 2022
@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 03:49 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Dec 20, 2022

Codecov Report

Merging #385 (e5c8cc5) into main (1974305) will increase coverage by 0.62%.
The diff coverage is 0.00%.

❗ Current head e5c8cc5 differs from pull request most recent head c6416bd. Consider uploading reports for the commit c6416bd to get more accurate results

@@            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              
Impacted Files Coverage Δ
pkg/gitutils/manifests.go 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

pkg/gitutils/manifests.go Outdated Show resolved Hide resolved
pkg/gitutils/manifests.go Outdated Show resolved Hide resolved
@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 06:06 — with GitHub Actions Inactive
@jayanth-tjvrr jayanth-tjvrr requested a review from bcle December 20, 2022 06:07
@@ -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:
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
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:

Copy link
Member

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

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

@cruizen cruizen Dec 20, 2022

Choose a reason for hiding this comment

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

Suggested change
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>

@@ -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)
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
return fmt.Errorf("failed to execute kustomization.yaml manifest: %s", err)
return fmt.Errorf("failed to execute kustomization.yaml manifest")

@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 14:45 — with GitHub Actions Inactive
@jayanth-tjvrr jayanth-tjvrr force-pushed the private/main/jayanth-reddy/ResolvingOverrideIssue branch from 74ac6ee to e5c8cc5 Compare December 20, 2022 15:12
@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 15:12 — with GitHub Actions Inactive
pkg/gitutils/manifests.go Show resolved Hide resolved
pkg/gitutils/manifests.go Show resolved Hide resolved
pkg/gitutils/manifests.go Show resolved Hide resolved
@@ -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()
Copy link
Collaborator

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

return fmt.Errorf("failed to create destination file %s: %s", dstPath, err)
}
_, err = io.Copy(dst, src)
_ = src.Close()
Copy link
Collaborator

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.

dstPath := path.Join(clusterPath, fileName)
dst, err := wt.Filesystem.Create(dstPath)
if err != nil {
_ = src.Close()
Copy link
Collaborator

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.

}
_, err = io.Copy(dst, src)
_ = src.Close()
_ = dst.Close()
Copy link
Collaborator

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

@jayanth-tjvrr jayanth-tjvrr temporarily deployed to arlon December 20, 2022 17:25 — with GitHub Actions Inactive
@jayanth-tjvrr jayanth-tjvrr requested a review from bcle December 20, 2022 17:26
Copy link
Collaborator

@bcle bcle left a 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()
Copy link
Collaborator

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.

@jayanth-tjvrr jayanth-tjvrr merged commit b72499e into main Dec 20, 2022
@Rohitrajak1807 Rohitrajak1807 deleted the private/main/jayanth-reddy/ResolvingOverrideIssue branch December 22, 2022 17:15
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.

3 participants