diff --git a/Dockerfile b/Dockerfile index bdd85c7a..fc5e8440 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,8 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY main.go main.go COPY api/ api/ -COPY controllers/ controllers/ +COPY cmd/ cmd/ COPY internal/ internal/ COPY pkg/ pkg/ @@ -24,7 +23,7 @@ COPY pkg/ pkg/ # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 7ba8b1c2..27b8822b 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ all: build .PHONY: help help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) ##@ Development @@ -74,7 +74,7 @@ update-scan-log: ## Update successful scan job pod log used in tests from templa trivy image nginxinc/nginx-unprivileged@sha256:6da1811b094adbea1eb34c3e48fc2833b1a11a351ec7b36cc390e740a64fbae4 \ --offline-scan --severity CRITICAL,HIGH --quiet --format template \ --template @$(shell pwd)/internal/trivy/templates/scan-report.json.tmpl \ - > controllers/testdata/scan-job-successful/successful-scan-job-pod.log.json + > internal/controller/stas/testdata/scan-job-successful/successful-scan-job-pod.log.json .PHONY: go-mod-tidy go-mod-tidy: ## Run go mod tidy against code. @@ -87,11 +87,11 @@ generate-all: manifests generate fmt fmt-imports go-mod-tidy ## Ensure all gener .PHONY: build build: generate fmt vet ## Build manager binary. - go build -o bin/manager main.go + go build -o bin/manager cmd/main.go .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go + go run ./cmd/main.go # If you wish built the manager image targeting other platforms you can use the --platform flag. # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. @@ -108,7 +108,7 @@ docker-push: ## Push docker image with the manager. # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=> than the export will fail) +# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=> then the export will fail) # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx @@ -117,7 +117,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - docker buildx create --name project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . - docker buildx rm project-v3-builder rm Dockerfile.cross @@ -174,14 +174,19 @@ CONTROLLER_TOOLS_VERSION ?= v0.11.1 GOIMPORTS_VERSION ?= v0.3.0 .PHONY: kustomize -kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. $(KUSTOMIZE): $(LOCALBIN) + @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \ + echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \ + rm -rf $(LOCALBIN)/kustomize; \ + fi test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/kustomize/v4@$(KUSTOMIZE_VERSION) .PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. +controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. $(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) + test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ + GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. diff --git a/PROJECT b/PROJECT index 78e1cc1a..53ebc819 100644 --- a/PROJECT +++ b/PROJECT @@ -1,6 +1,11 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: statnett.no layout: -- go.kubebuilder.io/v3 +- go.kubebuilder.io/v4-alpha +multigroup: true projectName: image-scanner-operator repo: github.com/statnett/image-scanner-operator resources: @@ -15,7 +20,7 @@ resources: domain: statnett.no group: stas kind: ContainerImageScan - path: github.com/statnett/image-scanner-operator/api/v1alpha1 + path: github.com/statnett/image-scanner-operator/api/stas/v1alpha1 version: v1alpha1 - controller: true group: batch diff --git a/api/v1alpha1/containerimagescan_types.go b/api/stas/v1alpha1/containerimagescan_types.go similarity index 100% rename from api/v1alpha1/containerimagescan_types.go rename to api/stas/v1alpha1/containerimagescan_types.go diff --git a/api/v1alpha1/groupversion_info.go b/api/stas/v1alpha1/groupversion_info.go similarity index 100% rename from api/v1alpha1/groupversion_info.go rename to api/stas/v1alpha1/groupversion_info.go diff --git a/api/v1alpha1/labels.go b/api/stas/v1alpha1/labels.go similarity index 100% rename from api/v1alpha1/labels.go rename to api/stas/v1alpha1/labels.go diff --git a/api/v1alpha1/vulnerability.go b/api/stas/v1alpha1/vulnerability.go similarity index 100% rename from api/v1alpha1/vulnerability.go rename to api/stas/v1alpha1/vulnerability.go diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/stas/v1alpha1/zz_generated.deepcopy.go similarity index 100% rename from api/v1alpha1/zz_generated.deepcopy.go rename to api/stas/v1alpha1/zz_generated.deepcopy.go diff --git a/main.go b/cmd/main.go similarity index 95% rename from main.go rename to cmd/main.go index c09065f4..5f349754 100644 --- a/main.go +++ b/cmd/main.go @@ -22,8 +22,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/cluster" "sigs.k8s.io/controller-runtime/pkg/healthz" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" - "github.com/statnett/image-scanner-operator/controllers" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" + "github.com/statnett/image-scanner-operator/internal/controller/stas" "github.com/statnett/image-scanner-operator/internal/metrics" "github.com/statnett/image-scanner-operator/internal/pod" "github.com/statnett/image-scanner-operator/internal/resources" @@ -136,7 +136,7 @@ func main() { os.Exit(1) } - if err = (&controllers.Indexer{}).SetupWithManager(mgr); err != nil { + if err = (&stas.Indexer{}).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to setup indexer") os.Exit(1) } @@ -149,7 +149,7 @@ func main() { os.Exit(1) } - if err = (&controllers.PodReconciler{ + if err = (&stas.PodReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Config: cfg, @@ -165,7 +165,7 @@ func main() { os.Exit(1) } - if err = (&controllers.ScanJobReconciler{ + if err = (&stas.ScanJobReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Config: cfg, @@ -175,7 +175,7 @@ func main() { os.Exit(1) } - if err = (&controllers.ContainerImageScanReconciler{ + if err = (&stas.ContainerImageScanReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Config: cfg, diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 0c84d406..f267772e 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -8,12 +8,12 @@ resources: patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_containerimagescans.yaml +#- patches/webhook_in_stas_containerimagescans.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_containerimagescans.yaml +#- patches/cainjection_in_stas_containerimagescans.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_containerimagescans.yaml b/config/crd/patches/cainjection_in_stas_containerimagescans.yaml similarity index 72% rename from config/crd/patches/cainjection_in_containerimagescans.yaml rename to config/crd/patches/cainjection_in_stas_containerimagescans.yaml index 646c82a1..17f2f3d8 100644 --- a/config/crd/patches/cainjection_in_containerimagescans.yaml +++ b/config/crd/patches/cainjection_in_stas_containerimagescans.yaml @@ -3,5 +3,5 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME name: containerimagescans.stas.statnett.no diff --git a/config/crd/patches/webhook_in_containerimagescans.yaml b/config/crd/patches/webhook_in_stas_containerimagescans.yaml similarity index 100% rename from config/crd/patches/webhook_in_containerimagescans.yaml rename to config/crd/patches/webhook_in_stas_containerimagescans.yaml diff --git a/config/operator/kustomization.yaml b/config/operator/kustomization.yaml index 5111f976..52d7d1c1 100644 --- a/config/operator/kustomization.yaml +++ b/config/operator/kustomization.yaml @@ -9,10 +9,12 @@ namespace: image-scanner namePrefix: image-scanner- # Labels to add to all resources and selectors. -commonLabels: - control-plane: image-scanner +labels: + - includeSelectors: true + pairs: + control-plane: image-scanner -bases: +resources: - ../crd - ../rbac - ../manager @@ -39,32 +41,102 @@ patchesStrategicMerge: # 'CERTMANAGER' needs to be enabled to use ca injection #- webhookcainjection_patch.yaml -# the following config is for teaching kustomize how to do var substitution -vars: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. -#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR -# objref: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert # this name should match the one in certificate.yaml -# fieldref: -# fieldpath: metadata.namespace -#- name: CERTIFICATE_NAME -# objref: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert # this name should match the one in certificate.yaml -#- name: SERVICE_NAMESPACE # namespace of the service -# objref: -# kind: Service -# version: v1 -# name: webhook-service -# fieldref: -# fieldpath: metadata.namespace -#- name: SERVICE_NAME -# objref: -# kind: Service -# version: v1 -# name: webhook-service +# Uncomment the following replacements to add the cert-manager CA injection annotations +#replacements: +# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +# fieldPath: .metadata.namespace # namespace of the certificate CR +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - select: +# kind: CustomResourceDefinition +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +# fieldPath: .metadata.name +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - select: +# kind: CustomResourceDefinition +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - source: # Add cert-manager annotation to the webhook Service +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.name # namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# - source: +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.namespace # namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true diff --git a/config/operator/manager_auth_proxy_patch.yaml b/config/operator/manager_auth_proxy_patch.yaml index 2137976a..b89b7002 100644 --- a/config/operator/manager_auth_proxy_patch.yaml +++ b/config/operator/manager_auth_proxy_patch.yaml @@ -31,7 +31,7 @@ spec: capabilities: drop: - "ALL" - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1 args: - "--secure-listen-address=0.0.0.0:8443" - "--upstream=http://127.0.0.1:8080/" diff --git a/config/rbac/kustomization.yaml b/config/rbac/kustomization.yaml index 8a8f4647..7d4ab53e 100644 --- a/config/rbac/kustomization.yaml +++ b/config/rbac/kustomization.yaml @@ -16,5 +16,5 @@ resources: #- auth_proxy_role.yaml #- auth_proxy_role_binding.yaml #- auth_proxy_client_clusterrole.yaml - - containerimagescan_editor_role.yaml - - containerimagescan_viewer_role.yaml + - stas_containerimagescan_editor_role.yaml + - stas_containerimagescan_viewer_role.yaml diff --git a/config/rbac/containerimagescan_editor_role.yaml b/config/rbac/stas_containerimagescan_editor_role.yaml similarity index 100% rename from config/rbac/containerimagescan_editor_role.yaml rename to config/rbac/stas_containerimagescan_editor_role.yaml diff --git a/config/rbac/containerimagescan_viewer_role.yaml b/config/rbac/stas_containerimagescan_viewer_role.yaml similarity index 100% rename from config/rbac/containerimagescan_viewer_role.yaml rename to config/rbac/stas_containerimagescan_viewer_role.yaml diff --git a/controllers/containerimagescan_controller.go b/internal/controller/stas/containerimagescan_controller.go similarity index 97% rename from controllers/containerimagescan_controller.go rename to internal/controller/stas/containerimagescan_controller.go index 3f2b859b..6e60fbbd 100644 --- a/controllers/containerimagescan_controller.go +++ b/internal/controller/stas/containerimagescan_controller.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -17,7 +17,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/controller" staserrors "github.com/statnett/image-scanner-operator/internal/errors" "github.com/statnett/image-scanner-operator/internal/trivy" diff --git a/controllers/containerimagescan_controller_test.go b/internal/controller/stas/containerimagescan_controller_test.go similarity index 97% rename from controllers/containerimagescan_controller_test.go rename to internal/controller/stas/containerimagescan_controller_test.go index 38439e1f..bc922008 100644 --- a/controllers/containerimagescan_controller_test.go +++ b/internal/controller/stas/containerimagescan_controller_test.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/trivy" "github.com/statnett/image-scanner-operator/internal/yaml" ) diff --git a/controllers/indexer.go b/internal/controller/stas/indexer.go similarity index 92% rename from controllers/indexer.go rename to internal/controller/stas/indexer.go index 5e5eac4c..3b4d2b64 100644 --- a/controllers/indexer.go +++ b/internal/controller/stas/indexer.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -6,7 +6,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) const ( diff --git a/controllers/predicates.go b/internal/controller/stas/predicates.go similarity index 97% rename from controllers/predicates.go rename to internal/controller/stas/predicates.go index d81ef951..b9b3bbcb 100644 --- a/controllers/predicates.go +++ b/internal/controller/stas/predicates.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "regexp" @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) var systemNamespaceRegex = regexp.MustCompile("^(kube-|openshift-).*") diff --git a/controllers/scan_job_controller.go b/internal/controller/stas/scan_job_controller.go similarity index 98% rename from controllers/scan_job_controller.go rename to internal/controller/stas/scan_job_controller.go index 2ffadbc7..46a700d7 100644 --- a/controllers/scan_job_controller.go +++ b/internal/controller/stas/scan_job_controller.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -22,7 +22,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/json" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/controller" staserrors "github.com/statnett/image-scanner-operator/internal/errors" "github.com/statnett/image-scanner-operator/internal/pod" diff --git a/controllers/scan_job_controller_test.go b/internal/controller/stas/scan_job_controller_test.go similarity index 98% rename from controllers/scan_job_controller_test.go rename to internal/controller/stas/scan_job_controller_test.go index dffd912a..6b294abf 100644 --- a/controllers/scan_job_controller_test.go +++ b/internal/controller/stas/scan_job_controller_test.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "bytes" @@ -18,7 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/trivy" "github.com/statnett/image-scanner-operator/internal/yaml" ) diff --git a/controllers/suite_test.go b/internal/controller/stas/suite_test.go similarity index 96% rename from controllers/suite_test.go rename to internal/controller/stas/suite_test.go index 86554fb6..7c752e90 100644 --- a/controllers/suite_test.go +++ b/internal/controller/stas/suite_test.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -25,7 +25,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/pod" "github.com/statnett/image-scanner-operator/pkg/operator" //+kubebuilder:scaffold:imports @@ -61,7 +61,7 @@ var _ = BeforeSuite(func() { By("bootstrapping test environment") testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, ErrorIfCRDPathMissing: true, } diff --git a/controllers/testdata/scan-job-failed/failed-scan-cis.yaml b/internal/controller/stas/testdata/scan-job-failed/failed-scan-cis.yaml similarity index 100% rename from controllers/testdata/scan-job-failed/failed-scan-cis.yaml rename to internal/controller/stas/testdata/scan-job-failed/failed-scan-cis.yaml diff --git a/controllers/testdata/scan-job-failed/failed-scan-job-pod.log b/internal/controller/stas/testdata/scan-job-failed/failed-scan-job-pod.log similarity index 100% rename from controllers/testdata/scan-job-failed/failed-scan-job-pod.log rename to internal/controller/stas/testdata/scan-job-failed/failed-scan-job-pod.log diff --git a/controllers/testdata/scan-job-successful-long/cis.yaml b/internal/controller/stas/testdata/scan-job-successful-long/cis.yaml similarity index 100% rename from controllers/testdata/scan-job-successful-long/cis.yaml rename to internal/controller/stas/testdata/scan-job-successful-long/cis.yaml diff --git a/controllers/testdata/scan-job-successful-long/scan-job-pod.log.json b/internal/controller/stas/testdata/scan-job-successful-long/scan-job-pod.log.json similarity index 100% rename from controllers/testdata/scan-job-successful-long/scan-job-pod.log.json rename to internal/controller/stas/testdata/scan-job-successful-long/scan-job-pod.log.json diff --git a/controllers/testdata/scan-job-successful/successful-scan-cis.yaml b/internal/controller/stas/testdata/scan-job-successful/successful-scan-cis.yaml similarity index 100% rename from controllers/testdata/scan-job-successful/successful-scan-cis.yaml rename to internal/controller/stas/testdata/scan-job-successful/successful-scan-cis.yaml diff --git a/controllers/testdata/scan-job-successful/successful-scan-job-pod.log.json b/internal/controller/stas/testdata/scan-job-successful/successful-scan-job-pod.log.json similarity index 100% rename from controllers/testdata/scan-job-successful/successful-scan-job-pod.log.json rename to internal/controller/stas/testdata/scan-job-successful/successful-scan-job-pod.log.json diff --git a/controllers/testdata/scan-job/cis.yaml b/internal/controller/stas/testdata/scan-job/cis.yaml similarity index 100% rename from controllers/testdata/scan-job/cis.yaml rename to internal/controller/stas/testdata/scan-job/cis.yaml diff --git a/controllers/testdata/scan-job/expected-scan-job.yaml b/internal/controller/stas/testdata/scan-job/expected-scan-job.yaml similarity index 100% rename from controllers/testdata/scan-job/expected-scan-job.yaml rename to internal/controller/stas/testdata/scan-job/expected-scan-job.yaml diff --git a/controllers/testdata/scan-job/workload-pod.yaml b/internal/controller/stas/testdata/scan-job/workload-pod.yaml similarity index 100% rename from controllers/testdata/scan-job/workload-pod.yaml rename to internal/controller/stas/testdata/scan-job/workload-pod.yaml diff --git a/controllers/types.go b/internal/controller/stas/types.go similarity index 91% rename from controllers/types.go rename to internal/controller/stas/types.go index 0d0c5d19..2b6addef 100644 --- a/controllers/types.go +++ b/internal/controller/stas/types.go @@ -1,10 +1,10 @@ -package controllers +package stas import ( "github.com/distribution/distribution/reference" corev1 "k8s.io/api/core/v1" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) type podContainerImage struct { diff --git a/controllers/types_test.go b/internal/controller/stas/types_test.go similarity index 96% rename from controllers/types_test.go rename to internal/controller/stas/types_test.go index c5c4ac61..abb747d9 100644 --- a/controllers/types_test.go +++ b/internal/controller/stas/types_test.go @@ -1,11 +1,11 @@ -package controllers +package stas import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) var _ = Describe("ImageReference", func() { diff --git a/controllers/workload_controller.go b/internal/controller/stas/workload_controller.go similarity index 98% rename from controllers/workload_controller.go rename to internal/controller/stas/workload_controller.go index a55535db..e9c5cb9d 100644 --- a/controllers/workload_controller.go +++ b/internal/controller/stas/workload_controller.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/controller" staserrors "github.com/statnett/image-scanner-operator/internal/errors" "github.com/statnett/image-scanner-operator/internal/hash" diff --git a/controllers/workload_controller_test.go b/internal/controller/stas/workload_controller_test.go similarity index 98% rename from controllers/workload_controller_test.go rename to internal/controller/stas/workload_controller_test.go index 2dbf7d1f..2988521d 100644 --- a/controllers/workload_controller_test.go +++ b/internal/controller/stas/workload_controller_test.go @@ -1,4 +1,4 @@ -package controllers +package stas import ( "context" @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) type TestWorkloadFactory func(namespacedName types.NamespacedName, labels map[string]string) client.Object diff --git a/internal/metrics/collector.go b/internal/metrics/collector.go index 2e7a036f..873d707e 100644 --- a/internal/metrics/collector.go +++ b/internal/metrics/collector.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" k8smetrics "sigs.k8s.io/controller-runtime/pkg/metrics" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/pkg/operator" ) diff --git a/internal/metrics/collector_test.go b/internal/metrics/collector_test.go index 4ba7f7ea..f9e1f174 100644 --- a/internal/metrics/collector_test.go +++ b/internal/metrics/collector_test.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) var _ = Describe("ContainerImageScan Collector", func() { diff --git a/internal/resources/suite_test.go b/internal/resources/suite_test.go index 03278ee4..b9fb1f33 100644 --- a/internal/resources/suite_test.go +++ b/internal/resources/suite_test.go @@ -14,7 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) var ( diff --git a/internal/trivy/scan_job.go b/internal/trivy/scan_job.go index 5d5c422a..34e40b16 100644 --- a/internal/trivy/scan_job.go +++ b/internal/trivy/scan_job.go @@ -12,7 +12,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/utils/pointer" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" "github.com/statnett/image-scanner-operator/internal/hash" "github.com/statnett/image-scanner-operator/pkg/operator" ) diff --git a/internal/trivy/scan_job_test.go b/internal/trivy/scan_job_test.go index e30d7fcd..db5bea39 100644 --- a/internal/trivy/scan_job_test.go +++ b/internal/trivy/scan_job_test.go @@ -6,7 +6,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) var _ = Describe("Creating scan Job container", func() { diff --git a/pkg/operator/config.go b/pkg/operator/config.go index 104caf35..4bd9a23e 100644 --- a/pkg/operator/config.go +++ b/pkg/operator/config.go @@ -3,7 +3,7 @@ package operator import ( "time" - stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" ) type Config struct {