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
Implement sync-by-replace option #3237
Conversation
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.
KindClusterRole = "ClusterRole" | ||
KindClusterRoleBinding = "ClusterRoleBinding" | ||
KindNameSpace = "NameSpace" | ||
KindDeployment = "Deployment" |
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.
exported const KindDeployment should have comment (or a comment on this block) or be unexported
Code coverage for golang is
|
Code coverage for golang is
|
Co-authored-by: knanao <50069775+knanao@users.noreply.github.com>
The following files are not gofmt-ed. By commenting pkg/app/piped/executor/kubernetes/kubernetes.go--- pkg/app/piped/executor/kubernetes/kubernetes.go.orig
+++ pkg/app/piped/executor/kubernetes/kubernetes.go
@@ -214,26 +214,26 @@
for _, m := range manifests {
annotation := m.GetAnnotations()[provider.LabelSyncReplace]
// Do not replace CRD because replace might delete CRD instance
- if annotation != provider.UserReplaceTrue || m.Key.IsCRD() {
- if err := applier.ApplyManifest(ctx, m); err != nil {
- lp.Errorf("Failed to apply manifest: %s (%w)", m.Key.ReadableLogString(), err)
- return err
- }
- lp.Successf("- applied manifest: %s", m.Key.ReadableLogString())
- continue
- }
- // Always try to replace first and create if it fails due to resource not found error.
- // This is because we cannot know whether resource already exists before executing command.
- err := applier.ReplaceManifest(ctx, m)
- if errors.Is(err, provider.ErrNotFound) {
- lp.Infof("Specified resource does not exist, so create the resource: %s (%w)", m.Key.ReadableLogString(), err)
- err = applier.CreateManifest(ctx, m)
- }
- if err != nil {
- lp.Errorf("Failed to replace or create manifest: %s (%w)", m.Key.ReadableLogString(), err)
- return err
- }
- lp.Successf("- replaced or created manifest: %s", m.Key.ReadableLogString())
+ if annotation != provider.UserReplaceTrue || m.Key.IsCRD() {
+ if err := applier.ApplyManifest(ctx, m); err != nil {
+ lp.Errorf("Failed to apply manifest: %s (%w)", m.Key.ReadableLogString(), err)
+ return err
+ }
+ lp.Successf("- applied manifest: %s", m.Key.ReadableLogString())
+ continue
+ }
+ // Always try to replace first and create if it fails due to resource not found error.
+ // This is because we cannot know whether resource already exists before executing command.
+ err := applier.ReplaceManifest(ctx, m)
+ if errors.Is(err, provider.ErrNotFound) {
+ lp.Infof("Specified resource does not exist, so create the resource: %s (%w)", m.Key.ReadableLogString(), err)
+ err = applier.CreateManifest(ctx, m)
+ }
+ if err != nil {
+ lp.Errorf("Failed to replace or create manifest: %s (%w)", m.Key.ReadableLogString(), err)
+ return err
+ }
+ lp.Successf("- replaced or created manifest: %s", m.Key.ReadableLogString())
}
lp.Successf("Successfully applied %d manifests", len(manifests))
|
Pretty good! |
Code coverage for golang is
|
Change option name from |
Got it. Look nice. |
Code coverage for golang is
|
Great work! Thank you. |
What this PR does / why we need it:
Implement pipecd.dev/sync-by-replace: "true" option. This enable use of kubectl replace/create instead of kubectl apply.
With this change, CRD is not supported for simplicity.
Which issue(s) this PR fixes:
Fixes #3173
Does this PR introduce a user-facing change?: