Skip to content

Commit

Permalink
fix: add missing step - set app label when creating resources
Browse files Browse the repository at this point in the history
Signed-off-by: minhthong582000 <[email protected]>
  • Loading branch information
minhthong582000 committed Jun 28, 2024
1 parent 9278fe7 commit 4ef6db3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gitops/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0-alpha.10
v0.1.0-alpha.11
9 changes: 9 additions & 0 deletions gitops/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ func (c *Controller) createResources(ctx context.Context, app *v1alpha1.Applicat
return fmt.Errorf("error getting resources with label: %s, %s", label, err)
}

// Set the label for the generated resources
label = map[string]string{
common.LabelKeyAppInstance: app.Name,
}
err = c.k8sUtil.SetLabelsForResources(generatedResources, label)
if err != nil {
return fmt.Errorf("error setting labels for resources: %s", err)
}

// Calculate diff
log.Infof("Diffing resources for application %s", app.Name)
diff, err := c.k8sUtil.DiffResources(currentResources, generatedResources)
Expand Down
2 changes: 2 additions & 0 deletions gitops/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ spec:
mock.EXPECT().GenerateManifests(gomock.Any()).Return(nil, nil)
mock.EXPECT().GetResourceWithLabel(gomock.Any()).Return(nil, nil)
mock.EXPECT().DiffResources(gomock.Any(), gomock.Any()).Return(true, nil)
mock.EXPECT().SetLabelsForResources(gomock.Any(), gomock.Any()).Return(nil)
mock.EXPECT().ApplyResources(gomock.Any()).Return(nil)
return mock
}(),
Expand Down Expand Up @@ -108,6 +109,7 @@ spec:
mock := k8sUtilMock.NewMockK8s(ctrl)
mock.EXPECT().GenerateManifests(gomock.Any()).Return(nil, nil)
mock.EXPECT().GetResourceWithLabel(gomock.Any()).Return(nil, nil)
mock.EXPECT().SetLabelsForResources(gomock.Any(), gomock.Any()).Return(nil)
mock.EXPECT().DiffResources(gomock.Any(), gomock.Any()).Return(false, nil)
return mock
}(),
Expand Down

0 comments on commit 4ef6db3

Please sign in to comment.