Skip to content

Commit

Permalink
feat: use apply operation instead of create
Browse files Browse the repository at this point in the history
Signed-off-by: minhthong582000 <[email protected]>
  • Loading branch information
minhthong582000 committed Nov 3, 2024
1 parent 690dc44 commit 028a2e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gitops/example/nginx/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ spec:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
cpu: 100m
memory: 256Mi
2 changes: 1 addition & 1 deletion gitops/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *Controller) createResources(ctx context.Context, app *v1alpha1.Applicat
// Create resources
for _, r := range generatedResources {
// TODO: use namespace from application spec
err := c.k8sUtil.CreateResource(ctx, r, app.GetNamespace())
err = c.k8sUtil.CreateResource(ctx, r, app.GetNamespace())
if err != nil {
return fmt.Errorf("error creating resources: %s", err)
}
Expand Down
6 changes: 5 additions & 1 deletion gitops/utils/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func (k *k8s) CreateResource(ctx context.Context, obj *unstructured.Unstructured
if apiResource.Namespaced {
dynInterface = k.dynClientSet.Resource(resource).Namespace(namespace)
}
_, err = dynInterface.Create(ctx, obj, metav1.CreateOptions{})

opts := metav1.ApplyOptions{
FieldManager: "application/apply-patch",
}
_, err = dynInterface.Apply(ctx, obj.GetName(), obj, opts)
return err
}

Expand Down

0 comments on commit 028a2e6

Please sign in to comment.