Skip to content

Commit

Permalink
update controller-gen (#33)
Browse files Browse the repository at this point in the history
* update controller-gen

Signed-off-by: Kim Tsao <[email protected]>

* update go version in codecov.yaml

Signed-off-by: Kim Tsao <[email protected]>

* update to use "go install" and update kustomize package

Signed-off-by: Kim Tsao <[email protected]>

* update dependencies per operator-sdk migration, add serviceAccountName to deployment manifest and remove redundant scc

Signed-off-by: Kim Tsao <[email protected]>

---------

Signed-off-by: Kim Tsao <[email protected]>
  • Loading branch information
kim-tsao authored Feb 17, 2023
1 parent 9de0213 commit d6da16a
Show file tree
Hide file tree
Showing 13 changed files with 592 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- name: Run tests
run: make test
- name: Codecov
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.17 as builder
FROM golang:1.18 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
VERSION ?= `cat VERSION`
# Default bundle image tag
BUNDLE_IMG ?= quay.io/devfile/registry-operator-bundle:$(VERSION)
CERT_MANAGER_VERSION ?= v1.8.0
CERT_MANAGER_VERSION ?= v1.11.0
ENABLE_WEBHOOKS ?= true

# Options for 'bundle-build'
Expand All @@ -17,10 +17,8 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
IMG ?= quay.io/devfile/registry-operator:next
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.21
ENVTEST_K8S_VERSION = 1.22

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -94,15 +92,13 @@ run: manifests generate fmt vet ## Run a controller from your host.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases



### check_fmt: Checks the formatting on files in repo
check_fmt:
ifeq ($(shell command -v goimports 2> /dev/null),)
$(error "goimports must be installed for this rule" && exit 1)
endif
ifeq ($(shell command -v addlicense 2> /dev/null),)
$(error "error addlicense must be installed for this rule: go get -u github.com/google/addlicense")
$(error "error addlicense must be installed for this rule: go install github.com/google/addlicense")
endif

if [[ $$(find . -not -path '*/\.*' -not -name '*zz_generated*.go' -name '*.go' -exec goimports -l {} \;) != "" ]]; then \
Expand All @@ -122,7 +118,7 @@ ifneq ($(shell command -v addlicense 2> /dev/null),)
@echo 'addlicense -v -f license_header.txt **/*.go'
@addlicense -v -f license_header.txt $$(find . -name '*.go')
else
$(error addlicense must be installed for this rule: go get -u github.com/google/addlicense)
$(error addlicense must be installed for this rule: go install github.com/google/addlicense)
endif

.PHONY: vet
Expand Down Expand Up @@ -158,7 +154,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 ;\
GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down Expand Up @@ -195,7 +191,7 @@ ifeq (, $(shell which kustomize))
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
GOFLAGS="" go install sigs.k8s.io/kustomize/kustomize/[email protected] ;\
go mod vendor ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
Expand All @@ -209,7 +205,7 @@ ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go get' any package $2 and install it to $1.
# go-get-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: clusterdevfileregistrieslists.registry.devfile.io
spec:
Expand Down Expand Up @@ -84,9 +84,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
8 changes: 1 addition & 7 deletions config/crd/bases/registry.devfile.io_devfileregistries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: devfileregistries.registry.devfile.io
spec:
Expand Down Expand Up @@ -132,9 +132,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: devfileregistrieslists.registry.devfile.io
spec:
Expand Down Expand Up @@ -84,9 +84,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
8 changes: 7 additions & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ spec:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: "RuntimeDefault"
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
Expand Down
5 changes: 5 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
name: manager
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: "RuntimeDefault"
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -60,4 +64,5 @@ spec:
requests:
cpu: 100m
memory: 20Mi
serviceAccountName: default
terminationGracePeriodSeconds: 10
18 changes: 8 additions & 10 deletions controllers/ensure.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2022 Red Hat, Inc.
Copyright 2020-2023 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,39 +20,37 @@ import (
"context"
"reflect"

"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
"github.com/devfile/registry-operator/pkg/registry"
routev1 "github.com/openshift/api/route/v1"
"github.com/prometheus/common/log"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

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

//use the controller log
// Check to see if the requested resource exists on the cluster. If it doesn't exist, create it and return.
err := r.Get(ctx, types.NamespacedName{Name: resourceName, Namespace: cr.Namespace}, resource)
if err != nil && errors.IsNotFound(err) {
generatedResource := r.generateResourceObject(cr, resource, labels, ingressDomain)
log.Info("Creating a new "+resourceType, resourceType+".Namespace", cr.Namespace+".Name", resourceName)
r.Log.Info("Creating a new resource ", resourceType, resourceType+".Namespace", cr.Namespace+".Name", resourceName)
err = r.Create(ctx, generatedResource)
if err != nil {
log.Error(err, "Failed to create new "+resourceType, resourceType+".Namespace", cr.Namespace, "Service.Name", cr.Namespace+".Name", resourceName)
r.Log.Error(err, "Failed to create new ", resourceType, resourceType+".Namespace", cr.Namespace, "Service.Name", cr.Namespace+".Name", resourceName)
return &ctrl.Result{}, err
}
return nil, nil
} else if err != nil {
log.Error(err, "Failed to get "+resourceType)
r.Log.Error(err, "Failed to get "+resourceType)
return &ctrl.Result{}, err
}

Expand All @@ -70,7 +68,7 @@ func (r *DevfileRegistryReconciler) ensure(ctx context.Context, cr *registryv1al
err = r.updateIngress(ctx, cr, ingressDomain, ingress)
}
if err != nil {
log.Error(err, "Failed to update "+resourceType)
r.Log.Error(err, "Failed to update "+resourceType)
return &ctrl.Result{}, err
}
return nil, nil
Expand Down
11 changes: 5 additions & 6 deletions controllers/update.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2022 Red Hat, Inc.
Copyright 2020-2023 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@ import (
registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
"github.com/devfile/registry-operator/pkg/registry"
routev1 "github.com/openshift/api/route/v1"
"github.com/prometheus/common/log"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (r *DevfileRegistryReconciler) updateDeployment(ctx context.Context, cr *re
}

if needsUpdating {
log.Info("Updating the DevfileRegistry deployment")
r.Log.Info("Updating the DevfileRegistry deployment")
return r.Update(ctx, dep)
}
return nil
Expand Down Expand Up @@ -168,15 +167,15 @@ func (r *DevfileRegistryReconciler) deleteOldPVCIfNeeded(ctx context.Context, cr
return nil
} else {
// Some other error occurred when listing PVCs, so log and return an error
log.Error(err, "Error listing PersistentVolumeClaims")
r.Log.Error(err, "Error listing PersistentVolumeClaims")
return err
}
} else {
// PVC found despite storage being disable, so delete it
log.Info(err, "Old PersistentVolumeClaim", pvc.Name, "found. Deleting it as storage has been disabled.")
r.Log.Info("Old PersistentVolumeClaim " + pvc.Name + " found. Deleting it as storage has been disabled.")
err = r.Delete(ctx, pvc)
if err != nil {
log.Error(err, "Error deleting PersistentVolumeClaim", pvc.Name)
r.Log.Error(err, "Error deleting PersistentVolumeClaim", pvc.Name)
return err
}
}
Expand Down
Loading

0 comments on commit d6da16a

Please sign in to comment.