Skip to content

Commit 307e528

Browse files
authored
v3 migration (#22)
* v3 migration Signed-off-by: Kim Tsao <[email protected]> * v3 migration - run go mod tidy Signed-off-by: Kim Tsao <[email protected]> * v3 migration - fix deprecated "go get" behaviour Signed-off-by: Kim Tsao <[email protected]> * v3 migration - fix formatting Signed-off-by: Kim Tsao <[email protected]> * v3 migration - use "go install" in Makefile Signed-off-by: Kim Tsao <[email protected]> * v3 migration - update install instructions under "kustomize" rule. "go install" fails on versioned pkg because replace directives are used in go.mod file Signed-off-by: Kim Tsao <[email protected]> * v3 migration - add -d option Signed-off-by: Kim Tsao <[email protected]> * v3 migration - add "go mod vendor " to fix inconsistent vendor issues Signed-off-by: Kim Tsao <[email protected]> * v3 migration - revert back to "go get" without -d flag Signed-off-by: Kim Tsao <[email protected]>
1 parent 30870a5 commit 307e528

23 files changed

+433
-305
lines changed

.github/workflows/ci.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ jobs:
5151
name: Check format
5252
run: |
5353
go get -u github.com/google/addlicense
54+
go install github.com/google/addlicense
5455
go get -u golang.org/x/tools/cmd/goimports
56+
go install golang.org/x/tools/cmd/goimports
5557
git reset HEAD --hard
5658
5759
make fmt

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1616
IMG ?= quay.io/devfile/registry-operator:next
1717

1818
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
19-
CRD_OPTIONS ?= "crd:trivialVersions=true"
19+
CRD_OPTIONS ?= "crd"
2020

2121
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2222
ifeq (,$(shell go env GOBIN))
@@ -120,7 +120,7 @@ ifeq (, $(shell which controller-gen))
120120
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
121121
cd $$CONTROLLER_GEN_TMP_DIR ;\
122122
go mod init tmp ;\
123-
GOFLAGS="" go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
123+
GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
124124
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
125125
}
126126
CONTROLLER_GEN=$(GOBIN)/controller-gen
@@ -135,7 +135,8 @@ ifeq (, $(shell which kustomize))
135135
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
136136
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
137137
go mod init tmp ;\
138-
GOFLAGS="" go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
138+
GOFLAGS="" go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
139+
go mod vendor ;\
139140
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
140141
}
141142
KUSTOMIZE=$(GOBIN)/kustomize

PROJECT

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
domain: devfile.io
2-
layout: go.kubebuilder.io/v2
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
go.sdk.operatorframework.io/v2: {}
6+
manifests.sdk.operatorframework.io/v2: {}
7+
scorecard.sdk.operatorframework.io/v2: {}
38
projectName: registry-operator
49
repo: github.com/devfile/registry-operator
510
resources:
6-
- controller: true
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
715
domain: devfile.io
816
group: registry
917
kind: DevfileRegistry
1018
path: github.com/devfile/registry-operator/api/v1alpha1
1119
version: v1alpha1
1220
version: "3"
13-
plugins:
14-
go.sdk.operatorframework.io/v2-alpha: {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
# The following patch adds a directive for certmanager to inject CA into the CRD
22
# CRD conversion requires k8s 1.13 or later.
3-
apiVersion: apiextensions.k8s.io/v1beta1
3+
apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
77
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
88
name: devfileregistries.registry.devfile.io
9+
spec:
10+
names:
11+
kind: DevfileRegistry
12+
plural: devfileregistries
13+
group: registry.devfile.io
14+
scope: Namespaced
15+
versions:
16+
- additionalPrinterColumns:
17+
- description: The URL for the Devfile Registry
18+
jsonPath: .status.url
19+
name: URL
20+
type: string
21+
name: v1alpha1
22+
served: true
23+
storage: true
24+
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
# The following patch enables conversion webhook for CRD
22
# CRD conversion requires k8s 1.13 or later.
3-
apiVersion: apiextensions.k8s.io/v1beta1
3+
apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
name: devfileregistries.registry.devfile.io
77
spec:
88
conversion:
99
strategy: Webhook
10-
webhookClientConfig:
11-
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12-
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13-
caBundle: Cg==
14-
service:
15-
namespace: system
16-
name: webhook-service
17-
path: /convert
10+
webhook:
11+
clientConfig:
12+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
13+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
14+
caBundle: Cg==
15+
service:
16+
namespace: system
17+
name: webhook-service
18+
path: /convert
19+
conversionReviewVersions:
20+
- v1
21+
group: registry.devfile.io
22+
names:
23+
kind: DevfileRegistry
24+
plural: devfileregistries
25+
scope: Namespaced
26+
versions:
27+
- additionalPrinterColumns:
28+
- description: The URL for the Devfile Registry
29+
jsonPath: .status.url
30+
name: URL
31+
type: string
32+
name: v1alpha1
33+
served: true
34+
storage: true

config/default/kustomization.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ bases:
2525
#- ../prometheus
2626

2727
patchesStrategicMerge:
28-
# Protect the /metrics endpoint by putting it behind auth.
29-
# If you want your controller-manager to expose the /metrics
30-
# endpoint w/o any authn/z, please comment the following line.
28+
# Protect the /metrics endpoint by putting it behind auth.
29+
# If you want your controller-manager to expose the /metrics
30+
# endpoint w/o any authn/z, please comment the following line.
3131
- manager_auth_proxy_patch.yaml
3232

33+
# Mount the controller config file for loading manager configurations
34+
# through a ComponentConfig type
35+
#- manager_config_patch.yaml
36+
3337
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3438
# crd/kustomization.yaml
3539
#- manager_webhook_patch.yaml
@@ -46,15 +50,15 @@ vars:
4650
# objref:
4751
# kind: Certificate
4852
# group: cert-manager.io
49-
# version: v1alpha2
53+
# version: v1
5054
# name: serving-cert # this name should match the one in certificate.yaml
5155
# fieldref:
5256
# fieldpath: metadata.namespace
5357
#- name: CERTIFICATE_NAME
5458
# objref:
5559
# kind: Certificate
5660
# group: cert-manager.io
57-
# version: v1alpha2
61+
# version: v1
5862
# name: serving-cert # this name should match the one in certificate.yaml
5963
#- name: SERVICE_NAMESPACE # namespace of the service
6064
# objref:

config/default/manager_auth_proxy_patch.yaml

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,25 @@ spec:
1010
spec:
1111
containers:
1212
- name: kube-rbac-proxy
13-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
13+
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
1414
args:
1515
- "--secure-listen-address=0.0.0.0:8443"
1616
- "--upstream=http://127.0.0.1:8080/"
1717
- "--logtostderr=true"
1818
- "--v=10"
1919
ports:
2020
- containerPort: 8443
21+
protocol: TCP
2122
name: https
23+
resources:
24+
limits:
25+
cpu: 500m
26+
memory: 128Mi
27+
requests:
28+
cpu: 5m
29+
memory: 64Mi
2230
- name: manager
2331
args:
24-
- "--metrics-addr=127.0.0.1:8080"
25-
- "--enable-leader-election"
32+
- "--health-probe-bind-address=:8081"
33+
- "--metrics-bind-address=127.0.0.1:8080"
34+
- "--leader-elect"

config/default/manager_webhook_patch.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ spec:
2121
secret:
2222
defaultMode: 420
2323
secretName: webhook-server-cert
24+
selector:
25+

config/default/webhookcainjection_patch.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This patch add annotation to admission webhook config and
22
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
3-
apiVersion: admissionregistration.k8s.io/v1beta1
3+
apiVersion: admissionregistration.k8s.io/v1
44
kind: MutatingWebhookConfiguration
55
metadata:
66
name: mutating-webhook-configuration
77
annotations:
88
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
99
---
10-
apiVersion: admissionregistration.k8s.io/v1beta1
10+
apiVersion: admissionregistration.k8s.io/v1
1111
kind: ValidatingWebhookConfiguration
1212
metadata:
1313
name: validating-webhook-configuration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
2+
kind: ControllerManagerConfig
3+
health:
4+
healthProbeBindAddress: :8081
5+
metrics:
6+
bindAddress: 127.0.0.1:8080
7+
webhook:
8+
port: 9443
9+
leaderElection:
10+
leaderElect: true
11+
resourceName: 1984829e.devfile.io

config/manager/kustomization.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
resources:
22
- manager.yaml
3+
4+
5+
generatorOptions:
6+
disableNameSuffixHash: true
7+
8+
configMapGenerator:
9+
- files:
10+
- controller_manager_config.yaml
11+
name: manager-config
12+
313
apiVersion: kustomize.config.k8s.io/v1beta1
414
kind: Kustomization
515
images:

config/manager/manager.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,38 @@ spec:
2121
replicas: 1
2222
template:
2323
metadata:
24+
annotations:
25+
kubectl.kubernetes.io/default-container: manager
2426
labels:
2527
control-plane: controller-manager
2628
app.kubernetes.io/name: devfileregistry-operator
2729
spec:
30+
securityContext:
31+
runAsNonRoot: true
2832
containers:
2933
- command:
3034
- /manager
3135
args:
32-
- --enable-leader-election
36+
- --leader-elect
3337
image: controller:latest
3438
imagePullPolicy: Always
3539
name: manager
40+
securityContext:
41+
allowPrivilegeEscalation: false
42+
livenessProbe:
43+
httpGet:
44+
path: /healthz
45+
port: 8081
46+
initialDelaySeconds: 15
47+
periodSeconds: 20
48+
readinessProbe:
49+
httpGet:
50+
path: /readyz
51+
port: 8081
52+
initialDelaySeconds: 5
53+
periodSeconds: 10
54+
# TODO(user): Configure the resources accordingly based on the project requirements.
55+
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3656
resources:
3757
limits:
3858
cpu: 100m

config/prometheus/monitor.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ spec:
1111
endpoints:
1212
- path: /metrics
1313
port: https
14+
scheme: https
15+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
16+
tlsConfig:
17+
insecureSkipVerify: true
1418
selector:
1519
matchLabels:
1620
control-plane: controller-manager

config/rbac/auth_proxy_service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ spec:
99
ports:
1010
- name: https
1111
port: 8443
12+
protocol: TCP
1213
targetPort: https
1314
selector:
1415
control-plane: controller-manager

config/rbac/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resources:
2+
- service_account.yaml
23
- role.yaml
34
- role_binding.yaml
45
- leader_election_role.yaml

config/rbac/leader_election_role.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ rules:
1717
- patch
1818
- delete
1919
- apiGroups:
20-
- ""
20+
- coordination.k8s.io
2121
resources:
22-
- configmaps/status
22+
- leases
2323
verbs:
24-
- get
25-
- update
26-
- patch
24+
- get
25+
- list
26+
- watch
27+
- create
28+
- update
29+
- patch
30+
- delete
2731
- apiGroups:
2832
- ""
2933
resources:

config/rbac/service_account.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: default
5+
namespace: system

controllers/devfileregistry_controller.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2020 Red Hat, Inc.
2+
// Copyright (c) 2020-2022 Red Hat, Inc.
33
// This program and the accompanying materials are made
44
// available under the terms of the Eclipse Public License 2.0
55
// which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -48,8 +48,7 @@ type DevfileRegistryReconciler struct {
4848
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
4949
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes;routes/custom-host,verbs=get;list;watch;create;update;patch;delete
5050

51-
func (r *DevfileRegistryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
52-
ctx := context.Background()
51+
func (r *DevfileRegistryReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5352
log := r.Log.WithValues("devfileregistry", req.NamespacedName)
5453

5554
// Fetch the DevfileRegistry instance

controllers/ensure.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
"context"
1616
"reflect"
1717

18+
"k8s.io/apimachinery/pkg/runtime"
19+
"sigs.k8s.io/controller-runtime/pkg/client"
20+
1821
registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
1922
"github.com/devfile/registry-operator/pkg/registry"
2023
routev1 "github.com/openshift/api/route/v1"
@@ -23,13 +26,12 @@ import (
2326
corev1 "k8s.io/api/core/v1"
2427
networkingv1 "k8s.io/api/networking/v1"
2528
"k8s.io/apimachinery/pkg/api/errors"
26-
"k8s.io/apimachinery/pkg/runtime"
2729
"k8s.io/apimachinery/pkg/types"
2830
ctrl "sigs.k8s.io/controller-runtime"
2931
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3032
)
3133

32-
func (r *DevfileRegistryReconciler) ensure(ctx context.Context, cr *registryv1alpha1.DevfileRegistry, resource runtime.Object, labels map[string]string, ingressDomain string) (*reconcile.Result, error) {
34+
func (r *DevfileRegistryReconciler) ensure(ctx context.Context, cr *registryv1alpha1.DevfileRegistry, resource client.Object, labels map[string]string, ingressDomain string) (*reconcile.Result, error) {
3335
resourceType := reflect.TypeOf(resource).Elem().Name()
3436
resourceName := getResourceName(resource, cr.Name)
3537

@@ -85,7 +87,7 @@ func getResourceName(resource runtime.Object, crName string) string {
8587
return registry.GenericResourceName(crName)
8688
}
8789

88-
func (r *DevfileRegistryReconciler) generateResourceObject(cr *registryv1alpha1.DevfileRegistry, resource runtime.Object, labels map[string]string, ingressDomain string) runtime.Object {
90+
func (r *DevfileRegistryReconciler) generateResourceObject(cr *registryv1alpha1.DevfileRegistry, resource client.Object, labels map[string]string, ingressDomain string) client.Object {
8991
switch resource.(type) {
9092
case *appsv1.Deployment:
9193
return registry.GenerateDeployment(cr, r.Scheme, labels)

0 commit comments

Comments
 (0)