Skip to content

Commit d9ec12d

Browse files
committed
Use new application-api and support new model in webhook.
New model has git url in Spec.Source.GitURL field, also Spec.ContainerImage isn't relevant when checking git source. Also allows updates of not important fields : Spec.ComponentName, Spec.Application Updates controller-gen version, since old version isn't able to parse new model spec. Fixes Dockerfile, because podman build didn't work because originally used directory didn't exist. Fixes CI, bumps go version to 1.24. Signed-off-by: Robert Cerven <rcerven@redhat.com>
1 parent 9b40094 commit d9ec12d

File tree

11 files changed

+97
-79
lines changed

11 files changed

+97
-79
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout application-service source code
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313
- name: Docker meta
1414
id: meta
1515
uses: docker/metadata-action@v4

.github/workflows/pr.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
OPERATOR_SDK_VERSION: v1.14.0
1313
PR_CHECK: true
1414
steps:
15-
- name: Set up Go 1.x
16-
uses: actions/setup-go@v2
17-
with:
18-
go-version: 1.21
1915
- name: Check out code into the Go module directory
20-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
2117
with:
2218
fetch-depth: 0
19+
- name: Set up Go 1.x
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version-file: './go.mod'
2323
- name: Cache Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
2424
uses: actions/cache@v3
2525
id: cache-operator-sdk
@@ -87,12 +87,6 @@ jobs:
8787
fi
8888
- name: Run Go Tests
8989
run: |
90-
# Temporarily adding a pact-go installation.
91-
# It should be gone once https://issues.redhat.com/browse/HAC-4879 is solved
92-
go get github.com/pact-foundation/pact-go/v2@2.x.x
93-
go install github.com/pact-foundation/pact-go/v2@2.x.x
94-
sudo /home/runner/go/bin/pact-go -l DEBUG install
95-
9690
make test
9791
- name: Check if Manager Kustomize has the right image
9892
run: |
@@ -102,7 +96,7 @@ jobs:
10296
uses: codecov/codecov-action@v2.1.0
10397
- name: Run Gosec Security Scanner
10498
run: |
105-
go install github.com/securego/gosec/v2/cmd/gosec@v2.19.0
99+
go install github.com/securego/gosec/v2/cmd/gosec@v2.24.7
106100
make gosec
107101
if [[ $? != 0 ]]
108102
then
@@ -123,15 +117,15 @@ jobs:
123117
runs-on: ubuntu-latest
124118
steps:
125119
- name: Check out code into the Go module directory
126-
uses: actions/checkout@v2
120+
uses: actions/checkout@v4
127121
with:
128122
fetch-depth: 0
129123
- name: Check if dockerimage build is working
130124
run: docker build -f ./Dockerfile .
131125
kube-linter:
132126
runs-on: ubuntu-latest
133127
steps:
134-
- uses: actions/checkout@v3
128+
- uses: actions/checkout@v4
135129
- name: Create ./.kube-linter/ for deployment files
136130
shell: bash
137131
run: mkdir -p ./.kube-linter/ && touch .kube-linter/manifests.yaml

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Build the manager binary
2-
FROM registry.access.redhat.com/ubi9/go-toolset:1.20.10 as builder
2+
FROM registry.access.redhat.com/ubi9/go-toolset:1.24.6-1762230058 AS builder
33

4-
WORKDIR /workspace
4+
WORKDIR /opt/app-root/src
55
# Copy the Go Modules manifests
66
COPY go.mod go.mod
77
COPY go.sum go.sum
@@ -32,7 +32,7 @@ ENV ENABLE_WEBHOOK_HTTP2=${ENABLE_WEBHOOK_HTTP2}
3232

3333
# Set the Git config for the AppData bot
3434
WORKDIR /
35-
COPY --from=builder /workspace/manager .
35+
COPY --from=builder /opt/app-root/src/manager .
3636

3737
COPY appdata.gitconfig /.gitconfig
3838
RUN chgrp -R 0 /.gitconfig && chmod -R g=u /.gitconfig

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ENABLE_WEBHOOK_HTTP2 ?=false
5050
APPLICATION_API_CRD = https://raw.githubusercontent.com/konflux-ci/application-api/main/manifests/application-api-customresourcedefinitions.yaml
5151

5252
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
53-
ENVTEST_K8S_VERSION = 1.22
53+
ENVTEST_K8S_VERSION = 1.28
5454

5555
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5656
ifeq (,$(shell go env GOBIN))
@@ -137,7 +137,7 @@ vet: ## Run go vet against code.
137137
.PHONY: gosec
138138
gosec:
139139
# Run this command to install gosec, if not installed:
140-
# go install github.com/securego/gosec/v2/cmd/gosec@v2.19.0
140+
# go install github.com/securego/gosec/v2/cmd/gosec@v2.24.7
141141
gosec -no-fail -fmt=sarif -out=gosec.sarif ./...
142142

143143
lint:
@@ -194,15 +194,15 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
194194

195195
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
196196
controller-gen: ## Download controller-gen locally if necessary.
197-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0)
197+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.3)
198198

199199
KUSTOMIZE = $(shell pwd)/bin/kustomize
200200
kustomize: ## Download kustomize locally if necessary.
201201
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5@v5.1.0)
202202

203203
ENVTEST = $(shell pwd)/bin/setup-envtest
204204
envtest: ## Download envtest-setup locally if necessary.
205-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@395cfc7486e652d19fe1b544a436f9852ba26e4f)
205+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.19)
206206

207207
DLV = $(shell pwd)/bin/dlv
208208
dlv:

config/webhook/manifests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: MutatingWebhookConfiguration
44
metadata:
5-
creationTimestamp: null
65
name: mutating-webhook-configuration
76
webhooks:
87
- admissionReviewVersions:
@@ -50,7 +49,6 @@ webhooks:
5049
apiVersion: admissionregistration.k8s.io/v1
5150
kind: ValidatingWebhookConfiguration
5251
metadata:
53-
creationTimestamp: null
5452
name: validating-webhook-configuration
5553
webhooks:
5654
- admissionReviewVersions:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/redhat-appstudio/application-service
22

3-
go 1.21
3+
go 1.24
44

55
require (
66
github.com/go-logr/logr v1.4.1
7-
github.com/konflux-ci/application-api v0.0.0-20240812090716-e7eb2ecfb409
7+
github.com/konflux-ci/application-api v0.0.0-20260311124621-11066ce65102
88
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d
99
github.com/onsi/ginkgo v1.16.5
1010
github.com/onsi/gomega v1.27.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
116116
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
117117
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
118118
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
119-
github.com/konflux-ci/application-api v0.0.0-20240812090716-e7eb2ecfb409 h1:hAhhcfc/EXW9eKS827PmyYuhk+Y4KkVOsT53Uo9OzCU=
120-
github.com/konflux-ci/application-api v0.0.0-20240812090716-e7eb2ecfb409/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
119+
github.com/konflux-ci/application-api v0.0.0-20260311124621-11066ce65102 h1:KJL7pB++31mmXdY56YKW04DJchPzpPDOPFwg/RlhohM=
120+
github.com/konflux-ci/application-api v0.0.0-20260311124621-11066ce65102/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
121121
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d h1:z7j3mglNoXvIrw5Vz/Ul+izoITRaqYURPIWrFoEyHgI=
122122
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d/go.mod h1:AcChx7FjpYSIkDvQgaUKyauuF0PXm3ivB5MqZSC9Eis=
123123
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

webhooks/component_webhook.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (r *ComponentWebhook) Default(ctx context.Context, obj runtime.Object) erro
6767
// Get the Application CR
6868
// Use the background context to ensure the operator's kubeconfig is used
6969
hasApplication := appstudiov1alpha1.Application{}
70-
err := r.client.Get(context.Background(), types.NamespacedName{Name: component.Spec.Application, Namespace: component.Namespace}, &hasApplication)
70+
err := r.client.Get(ctx, types.NamespacedName{Name: component.Spec.Application, Namespace: component.Namespace}, &hasApplication)
7171
if err != nil {
7272
// Don't block if the Application doesn't exist yet - this will retrigger whenever the resource is modified
7373
err = fmt.Errorf("unable to get the Application %s for Component %s, ignoring for now", component.Spec.Application, compName)
@@ -78,7 +78,7 @@ func (r *ComponentWebhook) Default(ctx context.Context, obj runtime.Object) erro
7878
var curComp appstudiov1alpha1.Component
7979
// Get the Component to update using the operator's kubeconfig so that there aren't any permissions issues setting the owner reference
8080
// Use the background context to ensure the operator's kubeconfig is used
81-
err := r.client.Get(context.Background(), types.NamespacedName{Name: compName, Namespace: component.Namespace}, &curComp)
81+
err := r.client.Get(ctx, types.NamespacedName{Name: compName, Namespace: component.Namespace}, &curComp)
8282
if err != nil {
8383
componentlog.Error(err, "unable to get current component, so skip setting owner reference")
8484
return nil
@@ -175,10 +175,13 @@ func (r *ComponentWebhook) ValidateCreate(ctx context.Context, obj runtime.Objec
175175

176176
if comp.Spec.Source.GitSource != nil && comp.Spec.Source.GitSource.URL != "" {
177177
if _, err := url.ParseRequestURI(comp.Spec.Source.GitSource.URL); err != nil {
178-
return fmt.Errorf(err.Error() + appstudiov1alpha1.InvalidSchemeGitSourceURL)
178+
return fmt.Errorf("%s%s", err.Error(), appstudiov1alpha1.InvalidSchemeGitSourceURL)
179179
}
180180
sourceSpecified = true
181-
} else if comp.Spec.ContainerImage != "" {
181+
} else if comp.Spec.Source.GitURL != "" {
182+
if _, err := url.ParseRequestURI(comp.Spec.Source.GitURL); err != nil {
183+
return fmt.Errorf("%s%s", err.Error(), appstudiov1alpha1.InvalidSchemeGitSourceURL)
184+
}
182185
sourceSpecified = true
183186
}
184187

@@ -208,14 +211,6 @@ func (r *ComponentWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj ru
208211
componentlog := r.log.WithValues("controllerKind", "Component").WithValues("name", newComp.Name).WithValues("namespace", newComp.Namespace)
209212
componentlog.Info("validating the update request")
210213

211-
if newComp.Spec.ComponentName != oldComp.Spec.ComponentName {
212-
return fmt.Errorf(appstudiov1alpha1.ComponentNameUpdateError, newComp.Spec.ComponentName)
213-
}
214-
215-
if newComp.Spec.Application != oldComp.Spec.Application {
216-
return fmt.Errorf(appstudiov1alpha1.ApplicationNameUpdateError, newComp.Spec.Application)
217-
}
218-
219214
if newComp.Spec.Source.GitSource != nil && oldComp.Spec.Source.GitSource != nil && (newComp.Spec.Source.GitSource.URL != oldComp.Spec.Source.GitSource.URL) {
220215
return fmt.Errorf(appstudiov1alpha1.GitSourceUpdateError, *(newComp.Spec.Source.GitSource))
221216
}

webhooks/component_webhook_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ var _ = Describe("Application validation webhook", func() {
7272

7373
err := k8sClient.Create(ctx, hasComp)
7474
Expect(err).Should(HaveOccurred())
75-
Expect(err.Error()).Should(ContainSubstring("spec.componentName in body should match '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'"))
76-
Expect(err.Error()).Should(ContainSubstring("spec.application in body should match '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'"))
75+
Expect(err.Error()).Should(ContainSubstring("spec.componentName in body should match '^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'"))
76+
Expect(err.Error()).Should(ContainSubstring("spec.application in body should match '^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'"))
7777

7878
hasComp.Spec.ComponentName = ComponentName
7979
hasComp.Spec.Application = HASAppName
@@ -149,26 +149,13 @@ var _ = Describe("Application validation webhook", func() {
149149
return !reflect.DeepEqual(createdHasComp, &appstudiov1alpha1.Component{})
150150
}, timeout, interval).Should(BeTrue())
151151

152-
// Update the Comp application
153-
createdHasComp.Spec.Application = "newapp"
154-
err := k8sClient.Update(ctx, createdHasComp)
155-
Expect(err).Should(HaveOccurred())
156-
Expect(err.Error()).Should(ContainSubstring(fmt.Errorf(appstudiov1alpha1.ApplicationNameUpdateError, createdHasComp.Spec.Application).Error()))
157-
158-
// Update the Comp component name
159-
createdHasComp.Spec.Application = hasComp.Spec.Application
160-
createdHasComp.Spec.ComponentName = "newcomp"
161-
err = k8sClient.Update(ctx, createdHasComp)
162-
Expect(err).Should(HaveOccurred())
163-
Expect(err.Error()).Should(ContainSubstring(fmt.Errorf(appstudiov1alpha1.ComponentNameUpdateError, createdHasComp.Spec.ComponentName).Error()))
164-
165152
// Update the Comp git src
166153
createdHasComp.Spec.ComponentName = hasComp.Spec.ComponentName
167154
createdHasComp.Spec.Source.GitSource.Context = hasComp.Spec.Source.GitSource.Context
168155
createdHasComp.Spec.Source.GitSource = &appstudiov1alpha1.GitSource{
169156
URL: "newlink",
170157
}
171-
err = k8sClient.Update(ctx, createdHasComp)
158+
err := k8sClient.Update(ctx, createdHasComp)
172159
Expect(err).Should(HaveOccurred())
173160
Expect(err.Error()).Should(ContainSubstring(fmt.Errorf(appstudiov1alpha1.GitSourceUpdateError, *createdHasComp.Spec.Source.GitSource).Error()))
174161

webhooks/component_webhook_unit_test.go

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ func TestComponentCreateValidatingWebhook(t *testing.T) {
187187
},
188188
},
189189
},
190+
{
191+
name: "component needs to have one source specified, new GitURL field",
192+
client: fakeClient,
193+
err: appstudiov1alpha1.MissingGitOrImageSource,
194+
newComp: appstudiov1alpha1.Component{
195+
ObjectMeta: v1.ObjectMeta{
196+
Name: "test-component",
197+
},
198+
Spec: appstudiov1alpha1.ComponentSpec{
199+
ComponentName: "component1",
200+
Application: "application1",
201+
Source: appstudiov1alpha1.ComponentSource{
202+
ComponentSourceUnion: appstudiov1alpha1.ComponentSourceUnion{
203+
GitURL: "",
204+
},
205+
},
206+
},
207+
},
208+
},
190209
{
191210
name: "valid component with invalid git scheme src",
192211
client: fakeClient,
@@ -209,8 +228,9 @@ func TestComponentCreateValidatingWebhook(t *testing.T) {
209228
},
210229
},
211230
{
212-
name: "valid component with container image",
231+
name: "invalid component without git source",
213232
client: fakeClient,
233+
err: appstudiov1alpha1.MissingGitOrImageSource,
214234
newComp: appstudiov1alpha1.Component{
215235
ObjectMeta: v1.ObjectMeta{
216236
Name: "test-component",
@@ -222,6 +242,44 @@ func TestComponentCreateValidatingWebhook(t *testing.T) {
222242
},
223243
},
224244
},
245+
{
246+
name: "valid component with git source",
247+
client: fakeClient,
248+
newComp: appstudiov1alpha1.Component{
249+
ObjectMeta: v1.ObjectMeta{
250+
Name: "test-component",
251+
},
252+
Spec: appstudiov1alpha1.ComponentSpec{
253+
ComponentName: "component1",
254+
Application: "application1",
255+
Source: appstudiov1alpha1.ComponentSource{
256+
ComponentSourceUnion: appstudiov1alpha1.ComponentSourceUnion{
257+
GitSource: &appstudiov1alpha1.GitSource{
258+
URL: "http://link",
259+
},
260+
},
261+
},
262+
},
263+
},
264+
},
265+
{
266+
name: "valid component with git source, new GitURL field",
267+
client: fakeClient,
268+
newComp: appstudiov1alpha1.Component{
269+
ObjectMeta: v1.ObjectMeta{
270+
Name: "test-component",
271+
},
272+
Spec: appstudiov1alpha1.ComponentSpec{
273+
ComponentName: "component1",
274+
Application: "application1",
275+
Source: appstudiov1alpha1.ComponentSource{
276+
ComponentSourceUnion: appstudiov1alpha1.ComponentSourceUnion{
277+
GitURL: "http://link",
278+
},
279+
},
280+
},
281+
},
282+
},
225283
{
226284
name: "validate succeeds but updating nudged component fails",
227285
client: fakeErrorClient,
@@ -238,6 +296,13 @@ func TestComponentCreateValidatingWebhook(t *testing.T) {
238296
BuildNudgesRef: []string{
239297
"alternating-error-comp",
240298
},
299+
Source: appstudiov1alpha1.ComponentSource{
300+
ComponentSourceUnion: appstudiov1alpha1.ComponentSourceUnion{
301+
GitSource: &appstudiov1alpha1.GitSource{
302+
URL: "http://link",
303+
},
304+
},
305+
},
241306
},
242307
},
243308
},
@@ -290,27 +355,6 @@ func TestComponentUpdateValidatingWebhook(t *testing.T) {
290355
updateComp appstudiov1alpha1.Component
291356
err string
292357
}{
293-
{
294-
name: "component name cannot be changed",
295-
client: fakeClient,
296-
err: fmt.Errorf(appstudiov1alpha1.ComponentNameUpdateError, "component1").Error(),
297-
updateComp: appstudiov1alpha1.Component{
298-
Spec: appstudiov1alpha1.ComponentSpec{
299-
ComponentName: "component1",
300-
},
301-
},
302-
},
303-
{
304-
name: "application name cannot be changed",
305-
client: fakeClient,
306-
err: fmt.Errorf(appstudiov1alpha1.ApplicationNameUpdateError, "application1").Error(),
307-
updateComp: appstudiov1alpha1.Component{
308-
Spec: appstudiov1alpha1.ComponentSpec{
309-
ComponentName: "component",
310-
Application: "application1",
311-
},
312-
},
313-
},
314358
{
315359
name: "git src url cannot be changed",
316360
client: fakeClient,

0 commit comments

Comments
 (0)