Skip to content

Commit cf729ff

Browse files
authored
pull secrets are also added/removed to namespace pull secret (#263)
application label can be empty STONEBLD-4018 Signed-off-by: Robert Cerven <rcerven@redhat.com>
1 parent ef472f7 commit cf729ff

12 files changed

Lines changed: 217 additions & 77 deletions

cmd/coverage_init.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ package main
77
// from the running binary during E2E tests.
88

99
import _ "github.com/konflux-ci/coverport/instrumentation/go" // starts coverage server via init()
10-

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ import (
4747
"sigs.k8s.io/controller-runtime/pkg/webhook"
4848

4949
"github.com/go-logr/logr"
50+
appstudioredhatcomv1alpha1 "github.com/konflux-ci/application-api/api/v1alpha1"
5051
imagerepositoryv1alpha1 "github.com/konflux-ci/image-controller/api/v1alpha1"
5152
controllers "github.com/konflux-ci/image-controller/internal/controller"
5253
controllermetrics "github.com/konflux-ci/image-controller/pkg/metrics"
5354
"github.com/konflux-ci/image-controller/pkg/quay"
54-
appstudioredhatcomv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
5555
// +kubebuilder:scaffold:imports
5656
)
5757

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ toolchain go1.24.6
77
require (
88
github.com/go-logr/logr v1.4.3
99
github.com/h2non/gock v1.2.0
10+
github.com/konflux-ci/application-api v0.0.0-20251126155256-d24742e8b026
1011
github.com/onsi/ginkgo/v2 v2.26.0
1112
github.com/onsi/gomega v1.38.2
1213
github.com/prometheus/client_golang v1.19.1
13-
github.com/redhat-appstudio/application-api v0.0.0-20231026192857-89515ad2504f
1414
go.uber.org/zap v1.27.0
1515
gotest.tools/v3 v3.5.2
1616
k8s.io/api v0.31.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
9494
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
9595
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127103713-95b5b5e04a62 h1:lMTed+H0EesSqsH3iQXtLoy/+SpbBT0BS1J0izeEtFM=
9696
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127103713-95b5b5e04a62/go.mod h1:WVMHU9A2464s/vjH1xOTm4LJDD4xP+VlEiU+KM0gkSU=
97+
github.com/konflux-ci/application-api v0.0.0-20251126155256-d24742e8b026 h1:Y6oKDSxmDY7JiNsrPm0ZRUcW+9cv20B71DuitI3sl28=
98+
github.com/konflux-ci/application-api v0.0.0-20251126155256-d24742e8b026/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
9799
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
98100
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
99101
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -135,8 +137,6 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G
135137
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
136138
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
137139
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
138-
github.com/redhat-appstudio/application-api v0.0.0-20231026192857-89515ad2504f h1:PoKf7gCV/g5blkzVlODkqeynmfIACcR7NqWF8eqnuec=
139-
github.com/redhat-appstudio/application-api v0.0.0-20231026192857-89515ad2504f/go.mod h1:YvckuKHe82eWloGk0/BpSw4YYG2owrGZAanztbOj3pQ=
140140
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
141141
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
142142
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

internal/controller/application_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3232
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
3333

34+
appstudioredhatcomv1alpha1 "github.com/konflux-ci/application-api/api/v1alpha1"
3435
imagerepositoryv1alpha1 "github.com/konflux-ci/image-controller/api/v1alpha1"
3536
l "github.com/konflux-ci/image-controller/pkg/logs"
36-
appstudioredhatcomv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
3737
)
3838

3939
const (
@@ -282,7 +282,7 @@ func (r *ApplicationPullSecretCreator) createApplicationPullSecret(ctx context.C
282282
return nil
283283
}
284284

285-
// udateServiceAccountWithApplicationPullSecret updates the ServiceAccount to include
285+
// updateServiceAccountWithApplicationPullSecret updates the ServiceAccount to include
286286
// the application pull secret as an imagePullSecret and as a Secret
287287
func (r *ApplicationPullSecretCreator) updateServiceAccountWithApplicationPullSecret(ctx context.Context, applicationPullSecretName string, namespace string) error {
288288
log := ctrllog.FromContext(ctx)

internal/controller/component_image_controller.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import (
3232
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
3333

3434
"github.com/go-logr/logr"
35+
appstudioredhatcomv1alpha1 "github.com/konflux-ci/application-api/api/v1alpha1"
3536
imagerepositoryv1alpha1 "github.com/konflux-ci/image-controller/api/v1alpha1"
3637
l "github.com/konflux-ci/image-controller/pkg/logs"
3738
"github.com/konflux-ci/image-controller/pkg/quay"
38-
appstudioredhatcomv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
3939
)
4040

4141
const (
@@ -156,7 +156,12 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
156156
}
157157

158158
if imageRepositoryFound == "" {
159-
imageRepositoryName := fmt.Sprintf("imagerepository-for-%s-%s", component.Spec.Application, component.Name)
159+
imageRepositoryName := ""
160+
if component.Spec.Application != "" {
161+
imageRepositoryName = fmt.Sprintf("imagerepository-for-%s-%s", component.Spec.Application, component.Name)
162+
} else {
163+
imageRepositoryName = fmt.Sprintf("imagerepository-for-%s", component.Name)
164+
}
160165
log.Info("Will create image repository", "ImageRepositoryName", imageRepositoryName, "ComponentName", component.Name)
161166

162167
imageRepository := &imagerepositoryv1alpha1.ImageRepository{
@@ -168,8 +173,7 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
168173
Name: imageRepositoryName,
169174
Namespace: component.Namespace,
170175
Labels: map[string]string{
171-
ApplicationNameLabelName: component.Spec.Application,
172-
ComponentNameLabelName: component.Name,
176+
ComponentNameLabelName: component.Name,
173177
},
174178
Annotations: map[string]string{
175179
updateComponentAnnotationName: "true",
@@ -182,6 +186,10 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
182186
},
183187
}
184188

189+
if component.Spec.Application != "" {
190+
imageRepository.ObjectMeta.Labels[ApplicationNameLabelName] = component.Spec.Application
191+
}
192+
185193
if err := r.Client.Create(ctx, imageRepository); err != nil {
186194
log.Error(err, "failed to create image repository", "ImageRepositoryName", imageRepositoryName, "ComponentName", component.Name)
187195
return ctrl.Result{}, err

internal/controller/component_image_controller_test.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ var _ = Describe("Component image controller", func() {
4444
Name: fmt.Sprintf("imagerepository-for-%s-%s", defaultComponentApplication, resourceImageProvisionKey.Name),
4545
Namespace: resourceImageProvisionKey.Namespace,
4646
}
47+
var imageRepositoryWithoutApplicationName = types.NamespacedName{
48+
Name: fmt.Sprintf("imagerepository-for-%s", resourceImageProvisionKey.Name),
49+
Namespace: resourceImageProvisionKey.Namespace,
50+
}
4751
var applicationKey = types.NamespacedName{Name: defaultComponentApplication, Namespace: imageTestNamespace}
4852
var componentSaName = getComponentSaName(resourceImageProvisionKey.Name)
4953

@@ -74,7 +78,8 @@ var _ = Describe("Component image controller", func() {
7478
It("should do image repository provision", func() {
7579
expectedVisibility := imagerepositoryv1alpha1.ImageVisibility("private")
7680
createComponent(componentConfig{
77-
ComponentKey: resourceImageProvisionKey,
81+
ComponentKey: resourceImageProvisionKey,
82+
ComponentApplication: defaultComponentApplication,
7883
Annotations: map[string]string{
7984
GenerateImageAnnotationName: "{\"visibility\": \"private\"}",
8085
},
@@ -104,10 +109,45 @@ var _ = Describe("Component image controller", func() {
104109
deleteImageRepository(imageRepositoryName)
105110
})
106111

112+
It("should do image repository provision, component doesn't have application", func() {
113+
expectedVisibility := imagerepositoryv1alpha1.ImageVisibility("private")
114+
createComponent(componentConfig{
115+
ComponentKey: resourceImageProvisionKey,
116+
Annotations: map[string]string{
117+
GenerateImageAnnotationName: "{\"visibility\": \"private\"}",
118+
},
119+
})
120+
// wait for component_image_controller to finish
121+
waitComponentAnnotationGone(resourceImageProvisionKey, GenerateImageAnnotationName)
122+
123+
imageRepositoriesList := &imagerepositoryv1alpha1.ImageRepositoryList{}
124+
Expect(k8sClient.List(ctx, imageRepositoriesList, &client.ListOptions{Namespace: resourceImageProvisionKey.Namespace})).To(Succeed())
125+
Expect(imageRepositoriesList.Items).To(HaveLen(1))
126+
127+
component := getComponent(resourceImageProvisionKey)
128+
// wait for imagerepository_controller to finish
129+
waitImageRepositoryFinalizerOnImageRepository(imageRepositoryWithoutApplicationName)
130+
imageRepository := getImageRepository(imageRepositoryWithoutApplicationName)
131+
132+
_, applicationLabelExists := imageRepository.ObjectMeta.Labels[ApplicationNameLabelName]
133+
Expect(applicationLabelExists).To(BeFalse())
134+
Expect(imageRepository.ObjectMeta.Labels[ComponentNameLabelName]).To(Equal(component.Name))
135+
Expect(imageRepository.Spec.Image.Visibility).To(Equal(expectedVisibility))
136+
Expect(imageRepository.ObjectMeta.OwnerReferences[0].UID).To(Equal(component.UID))
137+
Expect(imageRepository.ObjectMeta.Annotations[updateComponentAnnotationName]).To(BeEmpty())
138+
139+
component = getComponent(resourceImageProvisionKey)
140+
Expect(component.Annotations[ImageAnnotationName]).To(BeEmpty())
141+
Expect(component.Spec.ContainerImage).ToNot(BeEmpty())
142+
143+
deleteImageRepository(imageRepositoryWithoutApplicationName)
144+
})
145+
107146
It("should accept deprecated true value for repository options", func() {
108147
expectedVisibility := imagerepositoryv1alpha1.ImageVisibility("public")
109148
createComponent(componentConfig{
110-
ComponentKey: resourceImageProvisionKey,
149+
ComponentKey: resourceImageProvisionKey,
150+
ComponentApplication: defaultComponentApplication,
111151
Annotations: map[string]string{
112152
GenerateImageAnnotationName: "true",
113153
},
@@ -163,7 +203,7 @@ var _ = Describe("Component image controller", func() {
163203
})
164204

165205
It("should do nothing if generate annotation is not set", func() {
166-
createComponent(componentConfig{ComponentKey: resourceImageErrorKey})
206+
createComponent(componentConfig{ComponentKey: resourceImageErrorKey, ComponentApplication: defaultComponentApplication})
167207

168208
time.Sleep(ensureTimeout)
169209
waitComponentAnnotationGone(resourceImageErrorKey, GenerateImageAnnotationName)

0 commit comments

Comments
 (0)