From ca2a077d17df361ed6e6bbcc52f82342dad6761a Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Wed, 10 May 2023 15:08:57 -0700 Subject: [PATCH] adding golangci linting to project and correcting all errors found Signed-off-by: Adam D. Cornett --- .github/workflows/ci.yml | 12 ++++ .golangci.yaml | 67 ++++++++++++++++++ Makefile | 18 +++++ api/v1alpha1/groupversion_info.go | 4 +- controllers/operatorpipeline_controller.go | 13 ++-- controllers/suite_test.go | 6 +- internal/errors/errors.go | 8 ++- .../reconcilers/certified_image_stream.go | 7 +- .../reconcilers/marketplace_image_stream.go | 7 +- internal/reconcilers/pipeline_dependencies.go | 13 ++-- internal/reconcilers/pipeline_git_repo.go | 7 +- internal/reconcilers/status.go | 69 ++++++++++--------- internal/reconcilers/types.go | 4 +- main.go | 7 +- 14 files changed, 173 insertions(+), 69 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e61f4a..aedb1d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,5 +39,17 @@ jobs: - name: Manifests run: make manifests && git diff --exit-code + - name: Tidy + run: make tidy + + - name: Vet + run: make vet + + - name: Format + run: make fmt + + - name: Run golangci linting checks + run: make lint + - name: Test run: make test diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..dbcc016 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,67 @@ +run: + # Default timeout is 1m, up to give more room + timeout: 4m + +linters: + enable: + - asciicheck + - deadcode + - depguard + - gofumpt + - goimports + - importas + - revive + - misspell + - stylecheck + - tparallel + - unconvert + - unparam + - whitespace + +linters-settings: + importas: + alias: + - pkg: k8s.io/api/core/v1 + alias: corev1 + - pkg: k8s.io/api/rbac/v1 + alias: rbacv1 + - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + alias: metav1 + - pkg: k8s.io/apimachinery/pkg/api/errors + alias: apierrors + - pkg: sigs.k8s.io/controller-runtime + alias: ctrl + - pkg: sigs.k8s.io/controller-runtime/pkg/log + alias: logf + - pkg: k8s.io/apimachinery/pkg/util/runtime + alias: utilruntime + - pkg: k8s.io/client-go/kubernetes/scheme + alias: clientgoscheme + - pkg: k8s.io/apimachinery/pkg/util/yaml + alias: yamlutil + - pkg: github.com/operator-framework/api/pkg/operators/v1alpha1 + alias: operatorsv1a1 + - pkg: github.com/openshift/api/image/v1 + alias: imagev1 + - pkg: github.com/openshift/api/security/v1 + alias: securityv1 + - pkg: github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1 + alias: tekton + - pkg: github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1 + alias: certv1alpha1 + + revive: + rules: + - name: dot-imports + severity: warning + disabled: true + stylecheck: + dot-import-whitelist: + - github.com/onsi/gomega + - github.com/onsi/ginkgo + - github.com/onsi/ginkgo/v2 + goimports: + local-prefixes: github.com/redhat-openshift-ecosystem/operator-certification-operator + +output: + format: tab diff --git a/Makefile b/Makefile index 1d13d15..b2c6cd2 100644 --- a/Makefile +++ b/Makefile @@ -111,6 +111,10 @@ fmt: ## Run go fmt against code. vet: ## Run go vet against code. go vet ./... +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter checks. + $(GOLANGCI_LINT) run + .PHONY: test test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out @@ -281,3 +285,17 @@ test-sanity: tidy vet fmt tidy: go mod tidy git diff --exit-code + +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +GOLANGCI_LINT_VERSION ?= v1.52.2 +golangci-lint: $(GOLANGCI_LINT) +$(GOLANGCI_LINT): + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)) + +# go-get-tool will 'go get' any package $2 and install it to $1. +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +define go-install-tool +@[ -f $(1) ] || { \ +GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ +} +endef diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index c612530..711ace8 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1alpha1 contains API Schema definitions for the certification v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=certification.redhat.com +// +kubebuilder:object:generate=true +// +groupName=certification.redhat.com package v1alpha1 import ( diff --git a/controllers/operatorpipeline_controller.go b/controllers/operatorpipeline_controller.go index f070209..73100fa 100644 --- a/controllers/operatorpipeline_controller.go +++ b/controllers/operatorpipeline_controller.go @@ -19,11 +19,12 @@ package controllers import ( "context" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/reconcilers" + "github.com/go-logr/logr" imagev1 "github.com/openshift/api/image/v1" securityv1 "github.com/openshift/api/security/v1" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/reconcilers" tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -61,7 +62,7 @@ func (r *OperatorPipelineReconciler) Reconcile(ctx context.Context, req ctrl.Req reqLogger := logf.FromContext(ctx, "Request.Namespace", req.Namespace, "Request.Name", req.Name) reqLogger.Info("Reconciling OperatorPipeline") - currentPipeline := &certv1alpha1.OperatorPipeline{} + currentPipeline := &v1alpha1.OperatorPipeline{} err := r.Client.Get(ctx, req.NamespacedName, currentPipeline) if err != nil { if errors.IsNotFound(err) { @@ -77,7 +78,7 @@ func (r *OperatorPipelineReconciler) Reconcile(ctx context.Context, req ctrl.Req isOperatorPipelineMarkedToBeDeleted := currentPipeline.GetDeletionTimestamp() != nil if isOperatorPipelineMarkedToBeDeleted { if controllerutil.ContainsFinalizer(currentPipeline, operatorPipelineFinalizer) { - namespacePipelines := &certv1alpha1.OperatorPipelineList{} + namespacePipelines := &v1alpha1.OperatorPipelineList{} // creating listOptions inorder to know the number of OperatorPipeline resources in the given namespace // if last CR in namespace we can remove the ClusterRoleBinding associated with the namespace @@ -94,7 +95,7 @@ func (r *OperatorPipelineReconciler) Reconcile(ctx context.Context, req ctrl.Req } } - clusterPipelines := &certv1alpha1.OperatorPipelineList{} + clusterPipelines := &v1alpha1.OperatorPipelineList{} // not creating listOptions since we want to know the total number of OperatorPipelines in the entire cluster // if last CR in cluster we can remove the SCC and ClusterRole if err := r.Client.List(ctx, clusterPipelines); err != nil { @@ -209,7 +210,7 @@ func (r *OperatorPipelineReconciler) deleteClusterRoleBinding(ctx context.Contex // SetupWithManager sets up the controller with the Manager. func (r *OperatorPipelineReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&certv1alpha1.OperatorPipeline{}). + For(&v1alpha1.OperatorPipeline{}). Owns(&corev1.Secret{}). Owns(&imagev1.ImageStream{}). Owns(&tekton.Pipeline{}). diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 773b278..c67f363 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -20,6 +20,8 @@ import ( "path/filepath" "testing" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" @@ -29,8 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest/printer" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - certificationv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" //+kubebuilder:scaffold:imports ) @@ -66,7 +66,7 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - err = certificationv1alpha1.AddToScheme(scheme.Scheme) + err = v1alpha1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:scheme diff --git a/internal/errors/errors.go b/internal/errors/errors.go index 56f319d..5faf943 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -2,6 +2,8 @@ package errors import "errors" -var ErrSecretNotFound = errors.New("could not find existing secret") -var ErrInvalidSecret = errors.New("the secret does not contain a valid key") -var ErrGitRepoPathNotSpecified = errors.New("the GIT_REPO_PATH environment variable was not specified") +var ( + ErrSecretNotFound = errors.New("could not find existing secret") + ErrInvalidSecret = errors.New("the secret does not contain a valid key") + ErrGitRepoPathNotSpecified = errors.New("the GIT_REPO_PATH environment variable was not specified") +) diff --git a/internal/reconcilers/certified_image_stream.go b/internal/reconcilers/certified_image_stream.go index 37df052..7bc3fa4 100644 --- a/internal/reconcilers/certified_image_stream.go +++ b/internal/reconcilers/certified_image_stream.go @@ -3,10 +3,11 @@ package reconcilers import ( "context" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/objects" + "github.com/go-logr/logr" imagev1 "github.com/openshift/api/image/v1" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/objects" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -33,7 +34,7 @@ func NewCertifiedImageStreamReconciler(client client.Client, log logr.Logger, sc } // reconcileCertifiedImageStream will ensure that the certified operator ImageStream is present and up to date. -func (r *CertifiedImageStreamReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { +func (r *CertifiedImageStreamReconciler) Reconcile(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { key := types.NamespacedName{ Namespace: pipeline.Namespace, Name: certifiedIndex, diff --git a/internal/reconcilers/marketplace_image_stream.go b/internal/reconcilers/marketplace_image_stream.go index 62ed53c..7ad7582 100644 --- a/internal/reconcilers/marketplace_image_stream.go +++ b/internal/reconcilers/marketplace_image_stream.go @@ -3,10 +3,11 @@ package reconcilers import ( "context" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/objects" + "github.com/go-logr/logr" imagev1 "github.com/openshift/api/image/v1" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/objects" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -32,7 +33,7 @@ func NewMarketplaceImageStreamReconciler(client client.Client, log logr.Logger, } // reconcileMarketplaceImageStream will ensure that the Red Hat Marketplace ImageStream is present and up to date. -func (r *MarketplaceImageStreamReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { +func (r *MarketplaceImageStreamReconciler) Reconcile(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { key := types.NamespacedName{ Namespace: pipeline.Namespace, Name: marketplaceIndex, diff --git a/internal/reconcilers/pipeline_dependencies.go b/internal/reconcilers/pipeline_dependencies.go index 4880616..f5b4d96 100644 --- a/internal/reconcilers/pipeline_dependencies.go +++ b/internal/reconcilers/pipeline_dependencies.go @@ -6,21 +6,21 @@ import ( "os" "path/filepath" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" "github.com/go-git/go-git/v5" "github.com/go-logr/logr" securityv1 "github.com/openshift/api/security/v1" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" yamlutil "k8s.io/apimachinery/pkg/util/yaml" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/yaml" ) const ( @@ -54,7 +54,7 @@ func NewPipeDependenciesReconciler(client client.Client, log logr.Logger, scheme } } -func (r *PipelineDependenciesReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { +func (r *PipelineDependenciesReconciler) Reconcile(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { // Cloning operator-pipelines project to retrieve pipelines and tasks // yaml manifests that need to be applied beforehand // ref: https://github.com/redhat-openshift-ecosystem/certification-releases/blob/main/4.9/ga/ci-pipeline.md#step-6---install-the-certification-pipeline-and-dependencies-into-the-cluster @@ -110,7 +110,6 @@ func (r *PipelineDependenciesReconciler) Reconcile(ctx context.Context, pipeline tmpFile, err := r.modifyAndSaveTempClusterRoleBinding(ctx, filepath.Join(gitPath, baseManifestsPath, clusterRoleBindingYml), pipeline, new(rbacv1.ClusterRoleBinding)) if err != nil { return true, err - } defer os.Remove(tmpFile) @@ -121,7 +120,7 @@ func (r *PipelineDependenciesReconciler) Reconcile(ctx context.Context, pipeline return false, nil } -func (r *PipelineDependenciesReconciler) applyOrDeletePipeline(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline, applyManifest bool, yamlPath string) error { +func (r *PipelineDependenciesReconciler) applyOrDeletePipeline(ctx context.Context, pipeline *v1alpha1.OperatorPipeline, applyManifest bool, yamlPath string) error { if applyManifest { return r.applyManifests(ctx, yamlPath, pipeline, new(tekton.Pipeline), false) } @@ -169,7 +168,7 @@ func (r *PipelineDependenciesReconciler) applyManifests(ctx context.Context, fil if !errors.IsNotFound(err) { return err } - controllerutil.SetControllerReference(owner, obj, r.Scheme) + _ = controllerutil.SetControllerReference(owner, obj, r.Scheme) if err := r.Client.Create(ctx, obj); err != nil { log.Error(err, fmt.Sprintf("failed to create pipeline resource for file: %s", fileName)) return err diff --git a/internal/reconcilers/pipeline_git_repo.go b/internal/reconcilers/pipeline_git_repo.go index b8f2048..a70aa66 100644 --- a/internal/reconcilers/pipeline_git_repo.go +++ b/internal/reconcilers/pipeline_git_repo.go @@ -6,11 +6,12 @@ import ( "os" "path/filepath" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/errors" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-logr/logr" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/errors" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -33,7 +34,7 @@ func NewPipelineGitRepoReconciler(client client.Client, log logr.Logger, scheme } } -func (r *PipelineGitRepoReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { +func (r *PipelineGitRepoReconciler) Reconcile(_ context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { log := r.Log.WithName("gitrepo") gitMount, ok := os.LookupEnv("GIT_REPO_PATH") if !ok { diff --git a/internal/reconcilers/status.go b/internal/reconcilers/status.go index 7ac8b56..cfdc800 100644 --- a/internal/reconcilers/status.go +++ b/internal/reconcilers/status.go @@ -7,17 +7,18 @@ import ( "path/filepath" "strings" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/errors" + "github.com/go-git/go-git/v5" "github.com/go-logr/logr" imagev1 "github.com/openshift/api/image/v1" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/internal/errors" tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" yamlutil "k8s.io/apimachinery/pkg/util/yaml" @@ -27,10 +28,10 @@ import ( const ( defaultKubeconfigSecretName = "kubeconfig" defaultKubeconfigSecretKeyName = "kubeconfig" - defaultGithubApiSecretName = "github-api-token" - defaultGithubApiSecretKeyName = "GITHUB_TOKEN" - defaultPyxisApiSecretName = "pyxis-api-secret" - defaultPyxisApiSecretKeyName = "pyxis_api_key" + defaultGithubAPISecretName = "github-api-token" + defaultGithubAPISecretKeyName = "GITHUB_TOKEN" + defaultPyxisAPISecretName = "pyxis-api-secret" + defaultPyxisAPISecretKeyName = "pyxis_api_key" defaultDockerRegistrySecretKeyName = ".dockerconfigjson" defaultGithubSSHSecretKeyName = "id_rsa" ) @@ -56,7 +57,7 @@ func overrideSecretFromSpec(secretDefault, spec string) string { return secretDefault } -func (r *StatusReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { +func (r *StatusReconciler) Reconcile(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { origPipeline := pipeline.DeepCopy() pipeline.Status.ObservedGeneration = pipeline.Generation log := r.Log.WithValues("status.observedGeneration", pipeline.Generation) @@ -82,8 +83,8 @@ func (r *StatusReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1 return requeue, err } - githubApiSecret := overrideSecretFromSpec(defaultGithubApiSecretName, pipeline.Spec.GitHubSecretName) - requeue, err = r.reconcileSecretStatus(ctx, pipeline, "GithubApiSecret", githubApiSecret, defaultGithubApiSecretKeyName) + githubAPISecret := overrideSecretFromSpec(defaultGithubAPISecretName, pipeline.Spec.GitHubSecretName) + requeue, err = r.reconcileSecretStatus(ctx, pipeline, "GithubApiSecret", githubAPISecret, defaultGithubAPISecretKeyName) if requeue || err != nil { log.Error(err, "githubApiSecretStatus") return requeue, err @@ -97,8 +98,8 @@ func (r *StatusReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1 } } - pyxisApiSecret := overrideSecretFromSpec(defaultPyxisApiSecretName, pipeline.Spec.PyxisSecretName) - requeue, err = r.reconcileSecretStatus(ctx, pipeline, "PyxisApiSecret", pyxisApiSecret, defaultPyxisApiSecretKeyName) + pyxisAPISecret := overrideSecretFromSpec(defaultPyxisAPISecretName, pipeline.Spec.PyxisSecretName) + requeue, err = r.reconcileSecretStatus(ctx, pipeline, "PyxisApiSecret", pyxisAPISecret, defaultPyxisAPISecretKeyName) if requeue || err != nil { log.Error(err, "pyxisApiSecretStatus") return requeue, err @@ -156,7 +157,7 @@ func (r *StatusReconciler) Reconcile(ctx context.Context, pipeline *certv1alpha1 return false, nil } -func (r *StatusReconciler) commitStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline, log logr.Logger) { +func (r *StatusReconciler) commitStatus(ctx context.Context, pipeline *v1alpha1.OperatorPipeline, log logr.Logger) { err := r.Client.Status().Update(ctx, pipeline, &client.UpdateOptions{}) if err != nil && apierrors.IsConflict(err) { log.Info("conflict updating status") @@ -170,25 +171,25 @@ func (r *StatusReconciler) commitStatus(ctx context.Context, pipeline *certv1alp log.Info("updated status") } -func (r *StatusReconciler) setStatusInfo(status v1.ConditionStatus, reason string, message string, condition v1.Condition) v1.Condition { +func (r *StatusReconciler) setStatusInfo(status metav1.ConditionStatus, reason string, message string, condition metav1.Condition) metav1.Condition { condition.Status = status condition.Reason = reason condition.Message = message return condition } -func (r *StatusReconciler) conditionStatus(b bool) v1.ConditionStatus { +func (r *StatusReconciler) conditionStatus(b bool) metav1.ConditionStatus { if b { - return v1.ConditionTrue + return metav1.ConditionTrue } - return v1.ConditionFalse + return metav1.ConditionFalse } -func (r *StatusReconciler) reconcileImageStreamStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline, indexType, indexName string) (bool, error) { - readyCondition := v1.Condition{ +func (r *StatusReconciler) reconcileImageStreamStatus(ctx context.Context, pipeline *v1alpha1.OperatorPipeline, indexType, indexName string) (bool, error) { + readyCondition := metav1.Condition{ Type: fmt.Sprintf("%sReady", indexType), ObservedGeneration: pipeline.Generation, - Status: v1.ConditionUnknown, + Status: metav1.ConditionUnknown, } log := r.Log.WithValues("status.observedGeneration", pipeline.Generation) @@ -218,11 +219,11 @@ func (r *StatusReconciler) reconcileImageStreamStatus(ctx context.Context, pipel return false, nil } -func (r *StatusReconciler) reconcileSecretStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline, secretType, secretName, secretKey string) (bool, error) { - readyCondition := v1.Condition{ +func (r *StatusReconciler) reconcileSecretStatus(ctx context.Context, pipeline *v1alpha1.OperatorPipeline, secretType, secretName, secretKey string) (bool, error) { + readyCondition := metav1.Condition{ Type: fmt.Sprintf("%sReady", secretType), ObservedGeneration: pipeline.Generation, - Status: v1.ConditionUnknown, + Status: metav1.ConditionUnknown, } log := r.Log.WithValues("status.observedGeneration", pipeline.Generation) secret := &corev1.Secret{} @@ -280,11 +281,11 @@ func (r *StatusReconciler) reconcileSecretStatus(ctx context.Context, pipeline * return false, nil } -func (r *StatusReconciler) reconcilePipelineGitRepoStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { - readyCondition := v1.Condition{ +func (r *StatusReconciler) reconcilePipelineGitRepoStatus(_ context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { + readyCondition := metav1.Condition{ Type: "GitRepoReady", ObservedGeneration: pipeline.Generation, - Status: v1.ConditionUnknown, + Status: metav1.ConditionUnknown, } repo, err := git.PlainOpen(filepath.Join(os.Getenv("GIT_REPO_PATH"), "operator-pipeline")) @@ -317,11 +318,11 @@ func (r *StatusReconciler) reconcilePipelineGitRepoStatus(ctx context.Context, p return false, nil } -func (r *StatusReconciler) reconcilePipelineStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline, pipelineType, pipelineYaml string, pipelinePresent bool) (bool, error) { - readyCondition := v1.Condition{ +func (r *StatusReconciler) reconcilePipelineStatus(ctx context.Context, pipeline *v1alpha1.OperatorPipeline, pipelineType, pipelineYaml string, pipelinePresent bool) (bool, error) { + readyCondition := metav1.Condition{ Type: fmt.Sprintf("%sReady", pipelineType), ObservedGeneration: pipeline.Generation, - Status: v1.ConditionUnknown, + Status: metav1.ConditionUnknown, } if !pipelinePresent { @@ -356,7 +357,7 @@ func (r *StatusReconciler) reconcilePipelineStatus(ctx context.Context, pipeline return true, err } - var obj = new(tekton.Pipeline) + obj := new(tekton.Pipeline) if err = yamlutil.Unmarshal(b, &obj); err != nil { meta.SetStatusCondition(&pipeline.Status.Conditions, r.setStatusInfo( r.conditionStatus(false), @@ -386,11 +387,11 @@ func (r *StatusReconciler) reconcilePipelineStatus(ctx context.Context, pipeline return false, nil } -func (r *StatusReconciler) reconcileTasksStatus(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) { - readyCondition := v1.Condition{ +func (r *StatusReconciler) reconcileTasksStatus(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) { + readyCondition := metav1.Condition{ Type: "TasksReady", ObservedGeneration: pipeline.Generation, - Status: v1.ConditionUnknown, + Status: metav1.ConditionUnknown, } gitPath := filepath.Join(os.Getenv("GIT_REPO_PATH"), "operator-pipeline") @@ -416,7 +417,7 @@ func (r *StatusReconciler) reconcileTasksStatus(ctx context.Context, pipeline *c return true, err } - var obj = new(tekton.Task) + obj := new(tekton.Task) fileErrors := make([]string, 0, 10) unmarshalErrors := make([]string, 0, 10) getErrors := make([]string, 0, 10) diff --git a/internal/reconcilers/types.go b/internal/reconcilers/types.go index d89933e..a1bc0e7 100644 --- a/internal/reconcilers/types.go +++ b/internal/reconcilers/types.go @@ -3,9 +3,9 @@ package reconcilers import ( "context" - certv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" ) type Reconciler interface { - Reconcile(ctx context.Context, pipeline *certv1alpha1.OperatorPipeline) (bool, error) + Reconcile(ctx context.Context, pipeline *v1alpha1.OperatorPipeline) (bool, error) } diff --git a/main.go b/main.go index 36f7c4b..8aa3f1e 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,9 @@ import ( "flag" "os" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" + "github.com/redhat-openshift-ecosystem/operator-certification-operator/controllers" + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -27,8 +30,6 @@ import ( imagev1 "github.com/openshift/api/image/v1" securityv1 "github.com/openshift/api/security/v1" operatorsv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - certificationv1alpha1 "github.com/redhat-openshift-ecosystem/operator-certification-operator/api/v1alpha1" - "github.com/redhat-openshift-ecosystem/operator-certification-operator/controllers" tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -47,7 +48,7 @@ var ( func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(certificationv1alpha1.AddToScheme(scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme utilruntime.Must(tekton.AddToScheme(scheme))