diff --git a/Makefile b/Makefile index 746da296..e516b75e 100644 --- a/Makefile +++ b/Makefile @@ -1,127 +1,4 @@ -# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd" +include base.mk -LOCAL ?= - -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif - -# Setting SHELL to bash allows bash commands to be executed by recipes. -# This is a requirement for 'setup-envtest.sh' in the test target. -# Options are set to exit when a recipe line exits non-zero or a piped command fails. -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec - -all: lint test - -##@ General - -# The help target prints out all targets with their descriptions organized -# beneath their categories. The categories are represented by '##@' and the -# target descriptions by '##'. The awk commands is responsible for reading the -# entire set of makefiles included in this invocation, looking for lines of the -# file as xyz: ## something, and then pretty-format the target and help. Then, -# if there's a line with ##@ something, that gets pretty-printed as a category. -# More info on the usage of ANSI control characters for terminal formatting: -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters -# More info on the awk command: -# http://linuxcommand.org/lc3_adv_awk.php - -help: ## Display this help. - @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 - -fmt: ## Run go fmt against code. - go fmt ./... - -vet: ## Run go vet against code. - go vet ./... - -lint: golangcilint ## Run golangci-lint against code. - $(GOLANGCILINT) run - -ENVTEST_ASSETS_DIR=$(shell pwd)/testbin -test: fmt vet goimports ## Run tests. - mkdir -p ${ENVTEST_ASSETS_DIR} - test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out - -generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." - -##@ Setup - -CONTROLLER_GEN = $(shell pwd)/bin/controller-gen -controller-gen: ## Download controller-gen locally if necessary. - ## this is a necessary evil already reported by knative community https://github.com/kubernetes-sigs/controller-tools/ issue 560 - ## once the issue is fixed we can move to use the original package. the original line uses go-get-tools with sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 - $(call go-get-fork,$(CONTROLLER_GEN),https://github.com/katanomi/controller-tools,cmd/controller-gen,controller-gen) - -KUSTOMIZE = $(shell pwd)/bin/kustomize -kustomize: ## Download kustomize locally if necessary. - $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7) - -KO = $(shell pwd)/bin/ko -ko: ## Download ko locally if necessary. - $(call go-get-tool,$(KO),github.com/google/ko@v0.8.3) - -GOIMPORTS = $(shell pwd)/bin/goimports -goimports: ## Download goimports locally if necessary. - $(call go-get-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports) - $(GOIMPORTS) -w -l $(shell find . -path '.git' -prune -path './vendor' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print) - -GINKGO = $(shell pwd)/bin/ginkgo -ginkgo: ## Download ginkgo locally if necessary - $(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/ginkgo@v1.16.4) - -GOMOCK = $(shell pwd)/bin/mockgen -gomock: ## Download gomock locally if necessary. - $(call go-get-tool,$(GOMOCK),github.com/golang/mock/mockgen@v1.6.0) - -GOLANGCILINT = $(shell pwd)/bin/golangci-lint -golangcilint: ## Download golangci-lint locally if necessary - $(call go-get-tool,$(GOLANGCILINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.41.1) - -# go-get-tool will 'go get' any package $2 and install it to $1. -PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) -define go-get-tool -@[ -f $(1) ] || { \ -set -e ;\ -TMP_DIR=$$(mktemp -d) ;\ -cd $$TMP_DIR ;\ -go mod init tmp ;\ -echo "Downloading $(2)" ;\ -GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\ -rm -rf $$TMP_DIR ;\ -} -endef - -# go-get-fork is a "go-get-tool" like command to get temporary module forks. -define go-get-fork -@[ -f $(1) ] || { \ -set -e ;\ -TMP_DIR=$$(mktemp -d) ;\ -cd $$TMP_DIR ;\ -echo "Cloning $(2)" ;\ -git clone $(2) $(4) ;\ -cd $(4) ;\ -GOBIN=$(PROJECT_DIR)/bin go install ./$(3);\ -rm -rf $$TMP_DIR ;\ -} -endef - -# installyaml will check if a given namespace is present, if not will apply a yaml file and wait for a deployment to rollout -define installyaml -kubectl get ns $(1) > /dev/null ;\ -EXIT_CODE=$$?;\ -[ "$$EXIT_CODE" == "0" ] || { \ -set -e ;\ -kubectl apply -f $(2) ;\ -kubectl -n $(1) rollout status deploy/$(3) --timeout=10m ;\ -} -endef +manifests: controller-gen ##@Development Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. + # $(CONTROLLER_GEN) rbac:roleName=pkg paths="./..." diff --git a/apis/data/v1alpha1/labels_annotations.go b/apis/data/v1alpha1/labels_annotations.go index ee527cf3..698e816c 100644 --- a/apis/data/v1alpha1/labels_annotations.go +++ b/apis/data/v1alpha1/labels_annotations.go @@ -16,7 +16,7 @@ limitations under the License. package v1alpha1 -// storage resource type +// StorageResourceType storage resource type type StorageResourceType string const ( @@ -28,7 +28,7 @@ func (s StorageResourceType) String() string { return string(s) } -// Payload type +// PayloadType payload type type PayloadType string const ( @@ -43,7 +43,7 @@ func (p PayloadType) String() string { return string(p) } -// backend storage type +// BackendType backend storage type type BackendType string const ( diff --git a/apis/data/v1alpha1/zz_generated.deepcopy.go b/apis/data/v1alpha1/zz_generated.deepcopy.go index 836f256d..c4210c1d 100644 --- a/apis/data/v1alpha1/zz_generated.deepcopy.go +++ b/apis/data/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // +build !ignore_autogenerated /* -Copyright 2021 The Katanomi Authors. +Copyright 2022 The Katanomi Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/apis/meta/v1alpha1/auth_types.go b/apis/meta/v1alpha1/auth_types.go index 0820eff9..86da25dc 100644 --- a/apis/meta/v1alpha1/auth_types.go +++ b/apis/meta/v1alpha1/auth_types.go @@ -40,6 +40,7 @@ type AuthCheckOptions struct { } // AuthCheck consists of result for an auth check request +// +k8s:deepcopy-gen=false type AuthCheck struct { metav1.TypeMeta `json:",inline"` Spec *AuthCheckSpec `json:"spec,omitempty"` @@ -54,6 +55,8 @@ type AuthCheckSpec struct { Version string `json:"version,omitempty"` } +// +k8s:deepcopy-gen=false + type AuthCheckStatus struct { // Allowed describes if the headers used where accepted or not by the integrated system. // `True` when accepted, @@ -85,15 +88,15 @@ const ( NeedsAuthorizationAuthCheckReason = "NeedsAuthorization" ) -// +k8s:deepcopy-gen=false // AuthToken access token request response +// +k8s:deepcopy-gen=false type AuthToken struct { metav1.TypeMeta `json:",inline"` Status AuthTokenStatus `json:"status"` } -// +k8s:deepcopy-gen=false // AuthTokenStatus access token request response status +// +k8s:deepcopy-gen=false type AuthTokenStatus struct { // AccessTokenKey store the key for accessToken it is mainly for git clone as userName AccessTokenKey string `json:"accessTokenKey"` diff --git a/apis/meta/v1alpha1/buildmetadata_types.go b/apis/meta/v1alpha1/buildmetadata_types.go index 43c47ab1..37741293 100644 --- a/apis/meta/v1alpha1/buildmetadata_types.go +++ b/apis/meta/v1alpha1/buildmetadata_types.go @@ -25,7 +25,7 @@ const ( BuildMetadataKey = "builds.katanomi.dev/buildrun" ) -// This structure is a derivative of buildrun and is used for artifacts to record build information. +// BuildMetaData this structure is a derivative of buildrun and is used for artifacts to record build information. type BuildMetaData struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -59,7 +59,7 @@ type BuildRunGitStatus struct { Branch *BuildGitBranchStatus `json:"branch,omitempty"` } -// GitBranchStatus represent branch status of build run +// BuildGitBranchStatus represent branch status of build run type BuildGitBranchStatus struct { // Name of git branch Name string `json:"name"` diff --git a/apis/meta/v1alpha1/code_quality_types.go b/apis/meta/v1alpha1/code_quality_types.go index a9ea451a..9880ef88 100644 --- a/apis/meta/v1alpha1/code_quality_types.go +++ b/apis/meta/v1alpha1/code_quality_types.go @@ -50,7 +50,7 @@ type CodeQualityBranch struct { Metrics map[string]CodeQualityAnalyzeMetric `json:"metrics"` } -// CodeQualityAnalyzeResult present CodeQualityProject analyze result +// CodeQualityAnalyzeMetric present CodeQualityProject analyze result type CodeQualityAnalyzeMetric struct { // Value defines the value of this metric Value string `json:"value"` @@ -84,6 +84,7 @@ type CodeQualityTaskOption struct { PullRequest string `json:"pullRequest"` } +// CodeQualityLineChartOption code quality line chart option // +k8s:deepcopy-gen=false type CodeQualityLineChartOption struct { CodeQualityBaseOption diff --git a/apis/meta/v1alpha1/condition.go b/apis/meta/v1alpha1/condition.go index 06debfd8..d03d98dc 100644 --- a/apis/meta/v1alpha1/condition.go +++ b/apis/meta/v1alpha1/condition.go @@ -51,11 +51,11 @@ func SetConditionByErrorReason(conditionManager apis.ConditionManager, condition reason = ReasonForError(err) } message := err.Error() - if old == nil || old.IsTrue() || old.GetMessage() != message || old.GetReason() != reason { + if old == nil || !old.IsFalse() || old.GetMessage() != message || old.GetReason() != reason { conditionManager.MarkFalse(condition, reason, message) } } else { - if old == nil || old.IsFalse() { + if old == nil || !old.IsTrue() { conditionManager.MarkTrue(condition) } } diff --git a/apis/meta/v1alpha1/condition_test.go b/apis/meta/v1alpha1/condition_test.go index ef19fc6c..524514e3 100644 --- a/apis/meta/v1alpha1/condition_test.go +++ b/apis/meta/v1alpha1/condition_test.go @@ -362,6 +362,46 @@ func TestSetConditonByError(t *testing.T) { SetConditionByError(conditionManager, apis.ConditionSucceeded, nil) }) + t.Run("err is nil and from unknown status", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + conditionManager := apismock.NewMockConditionManager(ctrl) + + conditionManager.EXPECT().GetCondition(apis.ConditionSucceeded).Return(&apis.Condition{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + }) + + conditionManager.EXPECT(). + MarkTrue(apis.ConditionSucceeded). + Times(1) + + SetConditionByError(conditionManager, apis.ConditionSucceeded, nil) + }) + + t.Run("err is not nil and from unknown status", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + conditionManager := apismock.NewMockConditionManager(ctrl) + + err := errors.NewBadRequest("some reason") + + conditionManager.EXPECT().GetCondition(apis.ConditionSucceeded).Return(&apis.Condition{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + Message: err.Error(), + Reason: string(metav1.StatusReasonBadRequest), + }) + + conditionManager.EXPECT(). + MarkFalse(apis.ConditionSucceeded, string(metav1.StatusReasonBadRequest), err.Error()). + Times(1) + + SetConditionByError(conditionManager, apis.ConditionSucceeded, err) + }) + t.Run("Success condition not changed", func(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/apis/meta/v1alpha1/createdBy_types.go b/apis/meta/v1alpha1/createdBy_types.go index 25ed2abc..0dee1ba1 100644 --- a/apis/meta/v1alpha1/createdBy_types.go +++ b/apis/meta/v1alpha1/createdBy_types.go @@ -22,7 +22,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" ) -// Stores a list of created information. +// CreatedBy stores a list of created information. type CreatedBy struct { // Reference to the user that created the object. Any Kubernetes `Subject` is accepted. // +optional diff --git a/apis/meta/v1alpha1/createmeta_types.go b/apis/meta/v1alpha1/createmeta_types.go index 8c1147ec..224dd880 100644 --- a/apis/meta/v1alpha1/createmeta_types.go +++ b/apis/meta/v1alpha1/createmeta_types.go @@ -16,7 +16,7 @@ limitations under the License. package v1alpha1 -// CreateBranchParams params for create file in server +// CreateRepoFileParams params for create file in server type CreateRepoFileParams struct { // Branch target branch to create file Branch string `json:"branch"` diff --git a/apis/meta/v1alpha1/image_config_types.go b/apis/meta/v1alpha1/image_config_types.go index 2043d117..ed1246c3 100644 --- a/apis/meta/v1alpha1/image_config_types.go +++ b/apis/meta/v1alpha1/image_config_types.go @@ -24,6 +24,7 @@ import ( var ImageConfigGVK = GroupVersion.WithKind("ImageConfig") // ImageConfig object for plugins +// +k8s:deepcopy-gen=false type ImageConfig struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -31,6 +32,8 @@ type ImageConfig struct { Spec ImageConfigSpec `json:"spec"` } +// +k8s:deepcopy-gen=false + type ImageConfigSpec struct { Config v1.ImageConfig `json:"config"` } diff --git a/apis/meta/v1alpha1/listmeta_types.go b/apis/meta/v1alpha1/listmeta_types.go index f5d91c44..cb376ddd 100644 --- a/apis/meta/v1alpha1/listmeta_types.go +++ b/apis/meta/v1alpha1/listmeta_types.go @@ -91,7 +91,7 @@ func (opt ListOptions) GetSearchFirstElement(key string) (value string) { return } -// When ListOption page less than zero, set default value. +// DefaultPager when ListOption page less than zero, set default value. func (opt *ListOptions) DefaultPager() { if opt.ItemsPerPage < 1 { opt.ItemsPerPage = common.DefaultPerPage @@ -129,7 +129,7 @@ type ArtifactOptions struct { Artifact string `json:"artifact"` } -// IssueOption path params +// IssueOptions path params type IssueOptions struct { // Project identity name Identity string `json:"identity"` diff --git a/apis/meta/v1alpha1/objectcondition_set.go b/apis/meta/v1alpha1/objectcondition_set.go index 8e6c5e97..44c7db06 100644 --- a/apis/meta/v1alpha1/objectcondition_set.go +++ b/apis/meta/v1alpha1/objectcondition_set.go @@ -85,7 +85,7 @@ func (o *ObjectConditionSet) GetObjectConditions() ObjectConditions { return o.accessor.GetObjectConditions() } -// GetObjectConditions set conditions +// SetObjectConditions set conditions func (o *ObjectConditionSet) SetObjectConditions(objcs ObjectConditions) { o.accessor.SetObjectConditions(objcs) } diff --git a/apis/meta/v1alpha1/objectreference.go b/apis/meta/v1alpha1/objectreference.go index 3f6044e4..68518d80 100644 --- a/apis/meta/v1alpha1/objectreference.go +++ b/apis/meta/v1alpha1/objectreference.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/types" ) -// IsTheSameObjRef compares two corev1.ObjectReference comparing: +// IsTheSameObject compares two corev1.ObjectReference comparing: // APIVersion, Kind, Name and Namespace. All other attributes are ignored func IsTheSameObject(obj, compared corev1.ObjectReference) bool { return obj.APIVersion == compared.APIVersion && @@ -58,6 +58,7 @@ func GetNamespacedNameFromRef(ref *corev1.ObjectReference) (named types.Namespac return } +// ObjectRefOptionsFunc is a function that can be used to modify an object reference // +k8s:deepcopy-gen=false type ObjectRefOptionsFunc func(obj metav1.Object, ref *corev1.ObjectReference) diff --git a/apis/meta/v1alpha1/triggeredby_types.go b/apis/meta/v1alpha1/triggeredby_types.go index 80853db1..9ee7519d 100644 --- a/apis/meta/v1alpha1/triggeredby_types.go +++ b/apis/meta/v1alpha1/triggeredby_types.go @@ -42,7 +42,7 @@ var DefinitionTriggeredTypeValues = definitionTriggeredTypeValuesType{ Automated: "Automated", } -// Stores a list of triggered information such as: Entity that triggered, +// TriggeredBy stores a list of triggered information such as: Entity that triggered, // reference of an object that could have triggered, and event that triggered. type TriggeredBy struct { // Reference to the user that triggered the object. Any Kubernetes `Subject` is accepted. diff --git a/apis/meta/v1alpha1/zz_generated.deepcopy.go b/apis/meta/v1alpha1/zz_generated.deepcopy.go index 239a5ded..4f4b1775 100644 --- a/apis/meta/v1alpha1/zz_generated.deepcopy.go +++ b/apis/meta/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // +build !ignore_autogenerated /* -Copyright 2021 The Katanomi Authors. +Copyright 2022 The Katanomi Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -119,23 +119,64 @@ func (in *ArtifactSpec) DeepCopy() *ArtifactSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AuthCheck) DeepCopyInto(out *AuthCheck) { +func (in *Attribute) DeepCopyInto(out *Attribute) { *out = *in out.TypeMeta = in.TypeMeta - if in.Spec != nil { - in, out := &in.Spec, &out.Spec - *out = new(AuthCheckSpec) - (*in).DeepCopyInto(*out) + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Attribute. +func (in *Attribute) DeepCopy() *Attribute { + if in == nil { + return nil } - out.Status = in.Status + out := new(Attribute) + in.DeepCopyInto(out) + return out } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthCheck. -func (in *AuthCheck) DeepCopy() *AuthCheck { +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AttributeSpec) DeepCopyInto(out *AttributeSpec) { + *out = *in + if in.Types != nil { + in, out := &in.Types, &out.Types + *out = make([]IssueType, len(*in)) + copy(*out, *in) + } + if in.Priorities != nil { + in, out := &in.Priorities, &out.Priorities + *out = make([]IssuePriority, len(*in)) + copy(*out, *in) + } + if in.Statuses != nil { + in, out := &in.Statuses, &out.Statuses + *out = make([]AttributeStatus, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AttributeSpec. +func (in *AttributeSpec) DeepCopy() *AttributeSpec { if in == nil { return nil } - out := new(AuthCheck) + out := new(AttributeSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AttributeStatus) DeepCopyInto(out *AttributeStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AttributeStatus. +func (in *AttributeStatus) DeepCopy() *AttributeStatus { + if in == nil { + return nil + } + out := new(AttributeStatus) in.DeepCopyInto(out) return out } @@ -175,21 +216,6 @@ func (in *AuthCheckSpec) DeepCopy() *AuthCheckSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AuthCheckStatus) DeepCopyInto(out *AuthCheckStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthCheckStatus. -func (in *AuthCheckStatus) DeepCopy() *AuthCheckStatus { - if in == nil { - return nil - } - out := new(AuthCheckStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BlobStore) DeepCopyInto(out *BlobStore) { *out = *in @@ -247,6 +273,71 @@ func (in *BlobStoreSpec) DeepCopy() *BlobStoreSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Branch) DeepCopyInto(out *Branch) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Branch. +func (in *Branch) DeepCopy() *Branch { + if in == nil { + return nil + } + out := new(Branch) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BranchList) DeepCopyInto(out *BranchList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Branch, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BranchList. +func (in *BranchList) DeepCopy() *BranchList { + if in == nil { + return nil + } + out := new(BranchList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BranchSpec) DeepCopyInto(out *BranchSpec) { + *out = *in + out.Issue = in.Issue + out.Author = in.Author + if in.Address != nil { + in, out := &in.Address, &out.Address + *out = new(v1.Addressable) + (*in).DeepCopyInto(*out) + } + in.CodeInfo.DeepCopyInto(&out.CodeInfo) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BranchSpec. +func (in *BranchSpec) DeepCopy() *BranchSpec { + if in == nil { + return nil + } + out := new(BranchSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BuildGitBranchStatus) DeepCopyInto(out *BuildGitBranchStatus) { *out = *in @@ -392,6 +483,26 @@ func (in *CloudEvent) DeepCopy() *CloudEvent { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeInfo) DeepCopyInto(out *CodeInfo) { + *out = *in + if in.Address != nil { + in, out := &in.Address, &out.Address + *out = new(v1.Addressable) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeInfo. +func (in *CodeInfo) DeepCopy() *CodeInfo { + if in == nil { + return nil + } + out := new(CodeInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CodeQuality) DeepCopyInto(out *CodeQuality) { *out = *in @@ -621,6 +732,167 @@ func (in *CodeQualitySpec) DeepCopy() *CodeQualitySpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetrics) DeepCopyInto(out *CodeQualityTaskMetrics) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetrics. +func (in *CodeQualityTaskMetrics) DeepCopy() *CodeQualityTaskMetrics { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetrics) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsSpec) DeepCopyInto(out *CodeQualityTaskMetricsSpec) { + *out = *in + in.Summary.DeepCopyInto(&out.Summary) + out.Task = in.Task + out.Component = in.Component + if in.Metrics != nil { + in, out := &in.Metrics, &out.Metrics + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsSpec. +func (in *CodeQualityTaskMetricsSpec) DeepCopy() *CodeQualityTaskMetricsSpec { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsSpecComponent) DeepCopyInto(out *CodeQualityTaskMetricsSpecComponent) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsSpecComponent. +func (in *CodeQualityTaskMetricsSpecComponent) DeepCopy() *CodeQualityTaskMetricsSpecComponent { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsSpecComponent) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsSpecSummary) DeepCopyInto(out *CodeQualityTaskMetricsSpecSummary) { + *out = *in + if in.New != nil { + in, out := &in.New, &out.New + *out = new(CodeQualityTaskMetricsSpecSummaryOverview) + **out = **in + } + if in.Total != nil { + in, out := &in.Total, &out.Total + *out = new(CodeQualityTaskMetricsSpecSummaryOverview) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsSpecSummary. +func (in *CodeQualityTaskMetricsSpecSummary) DeepCopy() *CodeQualityTaskMetricsSpecSummary { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsSpecSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsSpecSummaryOverview) DeepCopyInto(out *CodeQualityTaskMetricsSpecSummaryOverview) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsSpecSummaryOverview. +func (in *CodeQualityTaskMetricsSpecSummaryOverview) DeepCopy() *CodeQualityTaskMetricsSpecSummaryOverview { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsSpecSummaryOverview) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsSpecTask) DeepCopyInto(out *CodeQualityTaskMetricsSpecTask) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsSpecTask. +func (in *CodeQualityTaskMetricsSpecTask) DeepCopy() *CodeQualityTaskMetricsSpecTask { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsSpecTask) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskMetricsStatus) DeepCopyInto(out *CodeQualityTaskMetricsStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskMetricsStatus. +func (in *CodeQualityTaskMetricsStatus) DeepCopy() *CodeQualityTaskMetricsStatus { + if in == nil { + return nil + } + out := new(CodeQualityTaskMetricsStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CodeQualityTaskOption) DeepCopyInto(out *CodeQualityTaskOption) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodeQualityTaskOption. +func (in *CodeQualityTaskOption) DeepCopy() *CodeQualityTaskOption { + if in == nil { + return nil + } + out := new(CodeQualityTaskOption) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Comment) DeepCopyInto(out *Comment) { + *out = *in + out.User = in.User + in.CreatedTime.DeepCopyInto(&out.CreatedTime) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Comment. +func (in *Comment) DeepCopy() *Comment { + if in == nil { + return nil + } + out := new(Comment) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CreateBranchParams) DeepCopyInto(out *CreateBranchParams) { *out = *in @@ -1771,10 +2043,188 @@ func (in *GitUserBaseInfo) DeepCopy() *GitUserBaseInfo { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Issue) DeepCopyInto(out *Issue) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Issue. +func (in *Issue) DeepCopy() *Issue { + if in == nil { + return nil + } + out := new(Issue) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueInfo) DeepCopyInto(out *IssueInfo) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueInfo. +func (in *IssueInfo) DeepCopy() *IssueInfo { + if in == nil { + return nil + } + out := new(IssueInfo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueList) DeepCopyInto(out *IssueList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Issue, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueList. +func (in *IssueList) DeepCopy() *IssueList { + if in == nil { + return nil + } + out := new(IssueList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueOptions) DeepCopyInto(out *IssueOptions) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueOptions. +func (in *IssueOptions) DeepCopy() *IssueOptions { + if in == nil { + return nil + } + out := new(IssueOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssuePriority) DeepCopyInto(out *IssuePriority) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssuePriority. +func (in *IssuePriority) DeepCopy() *IssuePriority { + if in == nil { + return nil + } + out := new(IssuePriority) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueProject) DeepCopyInto(out *IssueProject) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueProject. +func (in *IssueProject) DeepCopy() *IssueProject { + if in == nil { + return nil + } + out := new(IssueProject) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueSpec) DeepCopyInto(out *IssueSpec) { + *out = *in + out.Project = in.Project + if in.Address != nil { + in, out := &in.Address, &out.Address + *out = new(v1.Addressable) + (*in).DeepCopyInto(*out) + } + out.Priority = in.Priority + out.Assign = in.Assign + in.UpdatedTime.DeepCopyInto(&out.UpdatedTime) + out.Author = in.Author + if in.RelateIssues != nil { + in, out := &in.RelateIssues, &out.RelateIssues + *out = make([]RelateIssue, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.SubTasks != nil { + in, out := &in.SubTasks, &out.SubTasks + *out = make([]RelateIssue, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Comments != nil { + in, out := &in.Comments, &out.Comments + *out = make([]Comment, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueSpec. +func (in *IssueSpec) DeepCopy() *IssueSpec { + if in == nil { + return nil + } + out := new(IssueSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IssueType) DeepCopyInto(out *IssueType) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IssueType. +func (in *IssueType) DeepCopy() *IssueType { + if in == nil { + return nil + } + out := new(IssueType) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ListMeta) DeepCopyInto(out *ListMeta) { *out = *in in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Page != nil { + in, out := &in.Page, &out.Page + *out = new(int) + **out = **in + } + if in.ItemsPerPage != nil { + in, out := &in.ItemsPerPage, &out.ItemsPerPage + *out = new(int) + **out = **in + } + if in.TotalPages != nil { + in, out := &in.TotalPages, &out.TotalPages + *out = new(int) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ListMeta. @@ -1949,6 +2399,26 @@ func (in *ProjectSpec) DeepCopy() *ProjectSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RelateIssue) DeepCopyInto(out *RelateIssue) { + *out = *in + if in.Access != nil { + in, out := &in.Access, &out.Access + *out = new(v1.Addressable) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RelateIssue. +func (in *RelateIssue) DeepCopy() *RelateIssue { + if in == nil { + return nil + } + out := new(RelateIssue) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Repository) DeepCopyInto(out *Repository) { *out = *in @@ -2116,6 +2586,78 @@ func (in *TriggeredBy) DeepCopy() *TriggeredBy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *User) DeepCopyInto(out *User) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new User. +func (in *User) DeepCopy() *User { + if in == nil { + return nil + } + out := new(User) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserList) DeepCopyInto(out *UserList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]User, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserList. +func (in *UserList) DeepCopy() *UserList { + if in == nil { + return nil + } + out := new(UserList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserOptions) DeepCopyInto(out *UserOptions) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserOptions. +func (in *UserOptions) DeepCopy() *UserOptions { + if in == nil { + return nil + } + out := new(UserOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserSpec) DeepCopyInto(out *UserSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserSpec. +func (in *UserSpec) DeepCopy() *UserSpec { + if in == nil { + return nil + } + out := new(UserSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebhookRegisterSpec) DeepCopyInto(out *WebhookRegisterSpec) { *out = *in diff --git a/apis/validation/common_types_validation.go b/apis/validation/common_types_validation.go index 6490404a..20db04c1 100644 --- a/apis/validation/common_types_validation.go +++ b/apis/validation/common_types_validation.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package validation contains useful validation functions package validation import ( diff --git a/apis/validation/name_validation.go b/apis/validation/name_validation.go index 3f6dcff4..e46a1257 100644 --- a/apis/validation/name_validation.go +++ b/apis/validation/name_validation.go @@ -26,7 +26,7 @@ import ( const dns1123UnderscoreLabelFmt string = "[A-Za-z0-9]([-A-Za-z0-9_/]*[A-Za-z0-9])?" const dns1123UnderscoreLabelErrMsg string = "a lowercase RFC 1123 with underscore label must consist of lower case alphanumeric characters, '_' or '-', and must start and end with an alphanumeric character" -// DNS1123LabelMaxLength is a label's max length in DNS (RFC 1123) +// DNS1123UnderscoreLabelMaxLength is a label's max length in DNS (RFC 1123) const DNS1123UnderscoreLabelMaxLength int = validation.DNS1123LabelMaxLength var dns1123LabelRegexp = regexp.MustCompile("^" + dns1123UnderscoreLabelFmt + "$") diff --git a/client/context.go b/client/context.go index 4f641e55..94d4ffd2 100644 --- a/client/context.go +++ b/client/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package client contains functions to add and retrieve client from context package client import ( diff --git a/common/jsonbase64.go b/common/jsonbase64.go index fdfc49a3..b0e578a3 100644 --- a/common/jsonbase64.go +++ b/common/jsonbase64.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package common useful functionality for encoding and decoding objects package common import ( @@ -21,7 +22,7 @@ import ( "encoding/json" ) -//Convert obj to json string, and then encode it with base64. +// ToJSONBase64 convert obj to json string, and then encode it with base64. func ToJSONBase64(obj interface{}) (string, error) { objBytes, err := json.Marshal(obj) if err != nil { @@ -31,7 +32,7 @@ func ToJSONBase64(obj interface{}) (string, error) { return base64.StdEncoding.EncodeToString(objBytes), nil } -//Decode encodeStr using base64, and then use json to convert to obj. +// FromJSONBase64 decode encodeStr using base64, and then use json to convert to obj. func FromJSONBase64(encodeStr string, obj interface{}) error { decodeBytes, err := base64.StdEncoding.DecodeString(encodeStr) if err != nil { diff --git a/common/paginate.go b/common/paginate.go index e92442db..78c92cba 100644 --- a/common/paginate.go +++ b/common/paginate.go @@ -24,7 +24,7 @@ const ( DefaultPage = 1 ) -// This function implements the paging of List, inputting the total number of data (usually +// Paginate this function implements the paging of List, inputting the total number of data (usually // the length of Slice), the number of each page, and the page number. The function guarantees // that Begin and End do not exceed the total number of data. // diff --git a/controllers/interface.go b/controllers/interface.go index 1a00a2a1..50555494 100644 --- a/controllers/interface.go +++ b/controllers/interface.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package controllers implements the lazy loader logic for Katanomi. package controllers import ( diff --git a/errors/convert_error.go b/errors/convert_error.go index e232ca3c..0720b88d 100644 --- a/errors/convert_error.go +++ b/errors/convert_error.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package errors contains useful functionality for conversion errors package errors import ( diff --git a/errors/convert_resource.go b/errors/convert_resource.go index b1716e2e..a73d1fd4 100644 --- a/errors/convert_resource.go +++ b/errors/convert_resource.go @@ -18,7 +18,7 @@ package errors import "k8s.io/apimachinery/pkg/runtime/schema" -// GVKToGR convert schema GroupVersionKind to GroupVersionResource +// GVKToGVR convert schema GroupVersionKind to GroupVersionResource // Warning: this function just for show error info func GVKToGVR(gvk schema.GroupVersionKind) (gr schema.GroupVersionResource) { return schema.GroupVersionResource{ diff --git a/errors/convert_response_error.go b/errors/convert_response_error.go index f8378c83..168cfbe3 100644 --- a/errors/convert_response_error.go +++ b/errors/convert_response_error.go @@ -43,6 +43,8 @@ func ConvertResponseError(ctx context.Context, response *http.Response, err erro name = names[0] } else if response != nil && response.Request != nil && response.Request.URL != nil { name = response.Request.URL.String() + } else { + // use default } return errors.NewGenericServerResponse( diff --git a/errors/temporary_error.go b/errors/temporary_error.go index 8190ec51..94a3913c 100644 --- a/errors/temporary_error.go +++ b/errors/temporary_error.go @@ -45,7 +45,7 @@ func IsTemporaryError(err error) bool { } } -// TemporaryError +// TemporaryError is an error and has a Temporary function type TemporaryError interface { error Temporary() bool diff --git a/examples/sample-controller/apis/test/v1alpha1/zz_generated.deepcopy.go b/examples/sample-controller/apis/test/v1alpha1/zz_generated.deepcopy.go index ad8739bb..e3d46934 100644 --- a/examples/sample-controller/apis/test/v1alpha1/zz_generated.deepcopy.go +++ b/examples/sample-controller/apis/test/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // +build !ignore_autogenerated /* -Copyright 2021 The Katanomi Authors. +Copyright 2022 The Katanomi Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/examples/sample-controller/main.go b/examples/sample-controller/main.go index 525519ce..d89bbbdf 100644 --- a/examples/sample-controller/main.go +++ b/examples/sample-controller/main.go @@ -115,6 +115,8 @@ func WithCreateUpdateTimes() admission.TransformFunc { } else if apis.IsInUpdate(ctx) { annotations["updatedAt"] = now log.Debugw("adding updated time", "time", now) + } else { + // not changed } metaobj.SetAnnotations(annotations) } diff --git a/hash/hash.go b/hash/hash.go index d1eeaa40..32df59b3 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -14,8 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// copied from: https://github.com/kubernetes/kubernetes/blob/b695d79d4f967c403a96986f1750a35eb75e75f1/pkg/util/hash/hash.go - +// Package hash contains useful functionality for hashing. +// +// This package is copied from: +// https://github.com/kubernetes/kubernetes/blob/b695d79d4f967c403a96986f1750a35eb75e75f1/pkg/util/hash/hash.go package hash import ( diff --git a/logging/config.go b/logging/config.go index 90f172a8..4fc818dd 100644 --- a/logging/config.go +++ b/logging/config.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package logging contains useful functionality package logging import ( diff --git a/manager/context.go b/manager/context.go index 50f9e588..67778432 100644 --- a/manager/context.go +++ b/manager/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package manager contains functions to add and retrieve manager from context package manager import ( diff --git a/multicluster/context.go b/multicluster/context.go index cd6cad6d..ddbedebd 100644 --- a/multicluster/context.go +++ b/multicluster/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package multicluster contains functions to add and retrieve multi cluster from context package multicluster import ( diff --git a/multicluster/types.go b/multicluster/types.go index d7356bac..f493be84 100644 --- a/multicluster/types.go +++ b/multicluster/types.go @@ -30,6 +30,7 @@ import ( // DO NOT use this type for anything else +// Cluster is the Schema for the clusters API // +k8s:deepcopy-gen=false type Cluster struct { metav1.TypeMeta `json:",inline"` diff --git a/names/name.go b/names/name.go index 9af8ee0b..c8ae6361 100644 --- a/names/name.go +++ b/names/name.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package names contains useful functionality for generating names package names import ( @@ -43,7 +44,7 @@ const ( // copied from https://github.com/kubernetes/kubernetes/blob/c9fb3c8a1b3f407a5e84562843780aa3047d7d06/staging/src/k8s.io/apiserver/pkg/storage/names/generate.go#L49 // temporarily -// Generates a name with a random suffix +// GenerateName generates a name with a random suffix func GenerateName(base string) string { if len(base) > MaxGeneratedNameLength { base = base[:MaxGeneratedNameLength] diff --git a/namespace/context.go b/namespace/context.go index 59e9c590..ff21ab4c 100644 --- a/namespace/context.go +++ b/namespace/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package namespace contains functions to add and retrieve namespace from context package namespace import ( diff --git a/parallel/task.go b/parallel/task.go index c2feda40..3fb816d2 100644 --- a/parallel/task.go +++ b/parallel/task.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package parallel used to execute tasks in parallel package parallel import ( @@ -120,7 +121,7 @@ func (p *ParallelTasks) Name(name string) *ParallelTasks { // for _, item := range itemArrar { // pts.Add(genTask(item)) // } -// + func (p *ParallelTasks) Add(tasks ...Task) *ParallelTasks { p.tasks = append(p.tasks, tasks...) return p @@ -283,6 +284,7 @@ func isNil(i interface{}) bool { switch reflect.TypeOf(i).Kind() { case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice, reflect.Func: return reflect.ValueOf(i).IsNil() + default: + return false } - return false } diff --git a/plugin/client/auth.go b/plugin/client/auth.go index e2097d95..27965b5f 100644 --- a/plugin/client/auth.go +++ b/plugin/client/auth.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package client contains functions to add and retrieve auth from context package client import ( @@ -127,7 +128,7 @@ func (a *Auth) IsOAuth2() bool { return a.Type == v1alpha1.AuthTypeOAuth2 } -// IsBasic check auth is basic +// IsDynamic check auth is dynamic func (a *Auth) IsDynamic() bool { return a.Type == v1alpha1.AuthTypeDynamic } diff --git a/plugin/client/interface.go b/plugin/client/interface.go index f124a99a..2527e991 100644 --- a/plugin/client/interface.go +++ b/plugin/client/interface.go @@ -62,7 +62,7 @@ type AdditionalWebhookRegister interface { GetWebhookSupport() map[metav1alpha1.WebhookEventSupportType][]string } -// AuthCheck implements an authorization check method for plugins +// AuthChecker implements an authorization check method for plugins type AuthChecker interface { AuthCheck(ctx context.Context, option metav1alpha1.AuthCheckOptions) (*metav1alpha1.AuthCheck, error) } @@ -126,7 +126,7 @@ type ScanImage interface { ScanImage(ctx context.Context, params metav1alpha1.ArtifactOptions) error } -// GetImageConfig get image config +// ImageConfigGetter get image config type ImageConfigGetter interface { Interface GetImageConfig(ctx context.Context, params metav1alpha1.ArtifactOptions) (*metav1alpha1.ImageConfig, error) @@ -263,13 +263,13 @@ type GitCommitStatusCreator interface { CreateGitCommitStatus(ctx context.Context, payload metav1alpha1.CreateCommitStatusPayload) (metav1alpha1.GitCommitStatus, error) } -// GitRepositoryLister list git commit comment +// GitCommitCommentLister list git commit comment type GitCommitCommentLister interface { Interface ListGitCommitComment(ctx context.Context, option metav1alpha1.GitCommitOption, listOption metav1alpha1.ListOptions) (metav1alpha1.GitCommitCommentList, error) } -// GitRepositoryLister create git commit comment +// GitCommitCommentCreator create git commit comment type GitCommitCommentCreator interface { Interface CreateGitCommitComment(ctx context.Context, payload metav1alpha1.CreateCommitCommentPayload) (metav1alpha1.GitCommitComment, error) @@ -310,7 +310,7 @@ type ArtifactTriggerRegister interface { PushEventType() string } -// project management +// IssueLister issue lister type IssueLister interface { Interface ListIssues(ctx context.Context, params metav1alpha1.IssueOptions, option metav1alpha1.ListOptions) (*metav1alpha1.IssueList, error) diff --git a/plugin/component/metrics/metrics.go b/plugin/component/metrics/metrics.go index d432f544..b23a0188 100644 --- a/plugin/component/metrics/metrics.go +++ b/plugin/component/metrics/metrics.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package metrics provides prometheus metrics for restful package metrics import ( diff --git a/plugin/component/tracing/tracing.go b/plugin/component/tracing/tracing.go index 997166cc..70079bbf 100644 --- a/plugin/component/tracing/tracing.go +++ b/plugin/component/tracing/tracing.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package tracing contains useful functionality for tracing. package tracing import ( diff --git a/plugin/plugin.go b/plugin/plugin.go index b2b8946e..7a76e14f 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package plugin for building and running plugin package plugin import ( diff --git a/plugin/route/artifact.go b/plugin/route/artifact.go index 178d87ad..d7eea9e9 100644 --- a/plugin/route/artifact.go +++ b/plugin/route/artifact.go @@ -75,7 +75,7 @@ type artifactGetter struct { tags []string } -//NewArtifactGetter create a get artifact route with plugin client +// NewArtifactGet create a get artifact route with plugin client func NewArtifactGet(impl client.ArtifactGetter) Route { return &artifactGetter{ tags: []string{"projects", "repositories", "artifacts"}, @@ -119,7 +119,7 @@ type artifactDeleter struct { tags []string } -//NewArtifactDeleter create a delete artifact route with plugin client +// NewArtifactDelete create a delete artifact route with plugin client func NewArtifactDelete(impl client.ArtifactDeleter) Route { return &artifactDeleter{ tags: []string{"projects", "repositories", "artifacts"}, diff --git a/plugin/route/blobstore.go b/plugin/route/blobstore.go index 7446550b..bf096bd3 100644 --- a/plugin/route/blobstore.go +++ b/plugin/route/blobstore.go @@ -31,7 +31,7 @@ type blobStoreLister struct { tags []string } -//NewCodeQualityGetter create a get codeQuality route with plugin client +// NewBlobStoreLister create a get codeQuality route with plugin client func NewBlobStoreLister(impl client.BlobStoreLister) Route { return &blobStoreLister{ tags: []string{"blobStore"}, diff --git a/plugin/route/system.go b/plugin/route/system.go index a1de6e1e..1b063d60 100644 --- a/plugin/route/system.go +++ b/plugin/route/system.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package route contains useful functionality for the package route package route import ( diff --git a/pointer/pointer.go b/pointer/pointer.go index ab608fec..7704892b 100644 --- a/pointer/pointer.go +++ b/pointer/pointer.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package pointer provides helper functions for generating pointers package pointer // Bool is a helper routine that allocates a new bool value diff --git a/restclient/client.go b/restclient/client.go index 265e8b63..fc64e402 100644 --- a/restclient/client.go +++ b/restclient/client.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package restclient contains functions to add and retrieve rest client from context package restclient import ( diff --git a/scheme/context.go b/scheme/context.go index 890edaf9..1838e8f9 100644 --- a/scheme/context.go +++ b/scheme/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package scheme contains functions to add and retrieve scheme from context package scheme import ( diff --git a/secret/selector.go b/secret/selector.go index 970e867c..25e2f36c 100644 --- a/secret/selector.go +++ b/secret/selector.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package secret contains useful functionality for select secret package secret import ( @@ -40,7 +41,7 @@ import ( // A better secret selection solution that do not dependency on tool resource about tool secret // https://github.com/katanomi/spec/blob/main/3.core.credential.selection.md -// Encapsulate the configuration related to selecting secrets +// SelectSecretOption encapsulate the configuration related to selecting secrets type SelectSecretOption struct { // PerferredSecret will return the secret if it is be selected PerferredSecret types.NamespacedName diff --git a/sharedmain/app.go b/sharedmain/app.go index 9a2852f1..e77667dc 100644 --- a/sharedmain/app.go +++ b/sharedmain/app.go @@ -88,6 +88,7 @@ var ( InsecureSkipVerify bool ) +// ResourceLockFunc resouce lock function // Ref: https://github.com/kubernetes-sigs/controller-runtime/blob/1638a6a9b82dc1e0046c7a1006f12dacd9475f54/pkg/leaderelection/leader_election.go#L54 type ResourceLockFunc func(*rest.Config, recorder.Provider, leaderelection.Options) (resourcelock.Interface, error) diff --git a/sharedmain/main.go b/sharedmain/main.go index a2b5aea3..4ba1e6e9 100644 --- a/sharedmain/main.go +++ b/sharedmain/main.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package sharedmain contains useful functionality for main package sharedmain import ( @@ -122,5 +123,7 @@ func WatchLoggingConfigOrDie(ctx context.Context, cmw *cminformer.InformedWatche cmw.Watch(logging.ConfigMapName(), lvlMGR.Update()) } else if !apierrors.IsNotFound(err) { logger.Fatalw("Error reading ConfigMap "+logging.ConfigMapName(), zap.Error(err)) + } else { + // No mistakes, or tolerable mistakes } } diff --git a/system/env.go b/system/env.go index b123b688..57728663 100644 --- a/system/env.go +++ b/system/env.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package env provides functions to get the cluster name from environment package env import ( diff --git a/tracing/config.go b/tracing/config.go index eab46f7c..8f406749 100644 --- a/tracing/config.go +++ b/tracing/config.go @@ -17,12 +17,14 @@ limitations under the License. package tracing import ( + "context" "encoding/json" "os" "time" corev1 "k8s.io/api/core/v1" cm "knative.dev/pkg/configmap" + "knative.dev/pkg/logging" ) const ( @@ -132,6 +134,8 @@ func newTracingConfigFromConfigMap(config *corev1.ConfigMap) (*Config, error) { return nil, err } } + default: + logging.FromContext(context.TODO()).Warnw("unknown tracing backend", "backend", c.Backend) } return c, nil } diff --git a/tracing/doc.go b/tracing/doc.go new file mode 100644 index 00000000..fdf9d399 --- /dev/null +++ b/tracing/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package tracing contains tracing related functions. +package tracing diff --git a/tracing/tracing.go b/tracing/tracing.go index ab5a2cf6..5ceadfe3 100644 --- a/tracing/tracing.go +++ b/tracing/tracing.go @@ -17,6 +17,7 @@ limitations under the License. package tracing import ( + "context" "sync" "go.opentelemetry.io/otel" @@ -28,6 +29,7 @@ import ( semconv "go.opentelemetry.io/otel/semconv/v1.7.0" traceApi "go.opentelemetry.io/otel/trace" "go.uber.org/zap" + "knative.dev/pkg/logging" ) // NewTracing construct `Tracing` instance @@ -150,6 +152,8 @@ func (t *Tracing) exporter(config *Config) (exporter trace.SpanExporter, err err "err", err, "config", config, ) + default: + logging.FromContext(context.TODO()).Warnw("unknown tracing backend", "backend", config.Backend) } } diff --git a/user/matching/matchuser.go b/user/matching/matchuser.go index 9bfb0414..7e4c9464 100644 --- a/user/matching/matchuser.go +++ b/user/matching/matchuser.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package matching contains useful functionality for matching users package matching import ( @@ -32,6 +33,9 @@ func userMatch(userInfo authenticationv1.UserInfo, subjects []rbacv1.Subject) bo match = UserMatches(subject, userInfo) case rbacv1.GroupKind: match = UserGroupMatches(subject, userInfo) + default: + // do nothing + continue } if match { return true diff --git a/webhook/admission/context.go b/webhook/admission/context.go index 55a09ffb..b10b6841 100644 --- a/webhook/admission/context.go +++ b/webhook/admission/context.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package admission contains functions to add and retrieve admission request from context package admission import ( diff --git a/webhook/admission/defaulter.go b/webhook/admission/defaulter.go index c86db40e..281940ae 100644 --- a/webhook/admission/defaulter.go +++ b/webhook/admission/defaulter.go @@ -92,6 +92,8 @@ func (h *mutatingHandler) Handle(ctx context.Context, req admission.Request) adm ctx = apis.WithinUpdate(ctx, old) case admissionv1.Delete: ctx = apis.WithinDelete(ctx) + default: + // do nothing } // apply some common transformations before handling defaults diff --git a/webhook/admission/funcs.go b/webhook/admission/funcs.go index 46038aa7..a04d1125 100644 --- a/webhook/admission/funcs.go +++ b/webhook/admission/funcs.go @@ -36,7 +36,7 @@ func generateValidatePath(gvk schema.GroupVersionKind) string { gvk.Version + "-" + strings.ToLower(gvk.Kind) } -// returns a user based on the request information +// SubjectFromRequest returns a user based on the request information func SubjectFromRequest(req admission.Request) *rbacv1.Subject { sub := &rbacv1.Subject{} if strings.HasPrefix(req.UserInfo.Username, "system:serviceaccount:") { diff --git a/webhook/admission/transform.go b/webhook/admission/transform.go index baea9b49..871b746c 100644 --- a/webhook/admission/transform.go +++ b/webhook/admission/transform.go @@ -27,7 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) -// TransformFuncused to make common defaulting logic amongst multiple resource +// TransformFunc used to make common defaulting logic amongst multiple resource // using a context, an object and a request type TransformFunc func(context.Context, runtime.Object, admission.Request) diff --git a/webhook/admission/validator.go b/webhook/admission/validator.go index 65933c46..c1a7407f 100644 --- a/webhook/admission/validator.go +++ b/webhook/admission/validator.go @@ -141,6 +141,8 @@ func (h *validatingHandler) Handle(ctx context.Context, req admission.Request) a return convertToResponse(err) } } + default: + // do nothing } return admission.Allowed("") }