From dc4cac841e7b74e4d5f999b335950d3daa240580 Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Wed, 25 Oct 2023 20:20:42 +0200 Subject: [PATCH 1/2] chore: generate applyconfigurations for API --- Makefile | 25 ++- api/stas/v1alpha1/containerimagescan_types.go | 8 +- api/stas/v1alpha1/doc.go | 5 + api/stas/v1alpha1/groupversion_info.go | 7 +- api/stas/v1alpha1/zz_generated.deepcopy.go | 1 - go.mod | 2 +- .../applyconfiguration/internal/internal.go | 46 ++++ .../stas/v1alpha1/containerimagescan.go | 203 ++++++++++++++++++ .../stas/v1alpha1/containerimagescanspec.go | 69 ++++++ .../stas/v1alpha1/containerimagescanstatus.go | 89 ++++++++ .../applyconfiguration/stas/v1alpha1/image.go | 36 ++++ .../stas/v1alpha1/imagescanspec.go | 52 +++++ .../stas/v1alpha1/scanconfig.go | 32 +++ .../stas/v1alpha1/vulnerability.go | 86 ++++++++ .../stas/v1alpha1/vulnerabilitysummary.go | 47 ++++ .../stas/v1alpha1/workload.go | 50 +++++ internal/client/applyconfiguration/utils.go | 37 ++++ 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 api/stas/v1alpha1/doc.go create mode 100644 internal/client/applyconfiguration/internal/internal.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/containerimagescan.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/containerimagescanspec.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/containerimagescanstatus.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/image.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/imagescanspec.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/scanconfig.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/vulnerability.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/vulnerabilitysummary.go create mode 100644 internal/client/applyconfiguration/stas/v1alpha1/workload.go create mode 100644 internal/client/applyconfiguration/utils.go diff --git a/Makefile b/Makefile index fd246240..206d940e 100644 --- a/Makefile +++ b/Makefile @@ -45,9 +45,22 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases .PHONY: generate -generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. +generate: controller-gen k8s-client-gen ## Generate code required for K8s API and clients $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +GO_MODULE = $(shell go list -m) +API_DIRS = $(shell find api -mindepth 2 -type d | sed "s|^|$(shell go list -m)/|" | paste -sd ",") +.PHONY: k8s-client-gen +k8s-client-gen: applyconfiguration-gen + rm -rf internal/client/applyconfiguration + @echo ">> generating internal/client/applyconfiguration..." + $(APPLYCONFIGURATION_GEN) \ + --go-header-file hack/boilerplate.go.txt \ + --input-dirs "$(API_DIRS)" \ + --output-package "$(GO_MODULE)/internal/client/applyconfiguration" \ + --trim-path-prefix "$(GO_MODULE)" \ + --output-base "." + .PHONY: fmt fmt: ## Run go fmt against code. go fmt ./... @@ -159,6 +172,7 @@ $(LOCALBIN): mkdir -p $(LOCALBIN) ## Tool Binaries +APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest @@ -168,11 +182,20 @@ GCI_VERSION ?= v0.11.2 ## Tool Versions # renovate: datasource=go depName=sigs.k8s.io/kustomize/kustomize/v5 KUSTOMIZE_VERSION ?= v5.2.1 +# renovate: datasource=go depName=github.com/kubernetes/code-generator +CODE_GENERATOR_VERSION ?= v0.28.3 # renovate: datasource=go depName=sigs.k8s.io/controller-tools CONTROLLER_TOOLS_VERSION ?= v0.13.0 # renovate: datasource=go depName=golang.org/x/tools/cmd/goimports packageName=golang.org/x/tools GOIMPORTS_VERSION ?= v0.14.0 +.PHONY: applyconfiguration-gen +applyconfiguration-gen: $(APPLYCONFIGURATION_GEN) ## Download applyconfiguration-gen locally if necessary. +$(APPLYCONFIGURATION_GEN): $(LOCALBIN) + # FIXME: applyconfiguration-gen does not currently support any flag for obtaining version + test -s $(LOCALBIN)/applyconfiguration-gen || \ + GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODE_GENERATOR_VERSION) + .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. $(KUSTOMIZE): $(LOCALBIN) diff --git a/api/stas/v1alpha1/containerimagescan_types.go b/api/stas/v1alpha1/containerimagescan_types.go index 722003c5..94d32d1d 100644 --- a/api/stas/v1alpha1/containerimagescan_types.go +++ b/api/stas/v1alpha1/containerimagescan_types.go @@ -21,9 +21,10 @@ type Image struct { } type Workload struct { - metav1.GroupKind `json:",inline"` - Name string `json:"name"` - ContainerName string `json:"containerName"` + Group string `json:"group"` + Kind string `json:"kind"` + Name string `json:"name"` + ContainerName string `json:"containerName"` } type ScanConfig struct { @@ -110,6 +111,7 @@ type ContainerImageScanStatus struct { VulnerabilitySummary *VulnerabilitySummary `json:"vulnerabilitySummary,omitempty"` } +//+genclient //+kubebuilder:object:root=true //+kubebuilder:subresource:status //+kubebuilder:resource:shortName={cis} diff --git a/api/stas/v1alpha1/doc.go b/api/stas/v1alpha1/doc.go new file mode 100644 index 00000000..198fba1b --- /dev/null +++ b/api/stas/v1alpha1/doc.go @@ -0,0 +1,5 @@ +// Package v1alpha1 contains API Schema definitions for the system v1alpha1 API group +// FIXME: https://github.com/kubernetes/code-generator/issues/150 +// This was the only setup I could make work. Somehow the file location matters. +// +groupName=stas.statnett.no +package v1alpha1 diff --git a/api/stas/v1alpha1/groupversion_info.go b/api/stas/v1alpha1/groupversion_info.go index 4ca9d634..bbc94ec1 100644 --- a/api/stas/v1alpha1/groupversion_info.go +++ b/api/stas/v1alpha1/groupversion_info.go @@ -1,6 +1,5 @@ // Package v1alpha1 contains API Schema definitions for the stas v1alpha1 API group // +kubebuilder:object:generate=true -// +groupName=stas.statnett.no package v1alpha1 import ( @@ -9,11 +8,11 @@ import ( ) var ( - // GroupVersion is group version used to register these objects. - GroupVersion = schema.GroupVersion{Group: "stas.statnett.no", Version: "v1alpha1"} + // SchemeGroupVersion is group version used to register these objects. + SchemeGroupVersion = schema.GroupVersion{Group: "stas.statnett.no", Version: "v1alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme. - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme diff --git a/api/stas/v1alpha1/zz_generated.deepcopy.go b/api/stas/v1alpha1/zz_generated.deepcopy.go index 76cb2fa6..f3745888 100644 --- a/api/stas/v1alpha1/zz_generated.deepcopy.go +++ b/api/stas/v1alpha1/zz_generated.deepcopy.go @@ -241,7 +241,6 @@ func (in *VulnerabilitySummary) DeepCopy() *VulnerabilitySummary { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Workload) DeepCopyInto(out *Workload) { *out = *in - out.GroupKind = in.GroupKind } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Workload. diff --git a/go.mod b/go.mod index 853e8c52..7f86d621 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( sigs.k8s.io/cli-utils v0.35.0 sigs.k8s.io/controller-runtime v0.16.3 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 sigs.k8s.io/yaml v1.4.0 ) @@ -90,5 +91,4 @@ require ( k8s.io/apiextensions-apiserver v0.28.3 // indirect k8s.io/component-base v0.28.3 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect ) diff --git a/internal/client/applyconfiguration/internal/internal.go b/internal/client/applyconfiguration/internal/internal.go new file mode 100644 index 00000000..47f29e51 --- /dev/null +++ b/internal/client/applyconfiguration/internal/internal.go @@ -0,0 +1,46 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package internal + +import ( + "fmt" + "sync" + + typed "sigs.k8s.io/structured-merge-diff/v4/typed" +) + +func Parser() *typed.Parser { + parserOnce.Do(func() { + var err error + parser, err = typed.NewParser(schemaYAML) + if err != nil { + panic(fmt.Sprintf("Failed to parse schema: %v", err)) + } + }) + return parser +} + +var parserOnce sync.Once +var parser *typed.Parser +var schemaYAML = typed.YAMLObject(`types: +- name: __untyped_atomic_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic +- name: __untyped_deduced_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_deduced_ + elementRelationship: separable +`) diff --git a/internal/client/applyconfiguration/stas/v1alpha1/containerimagescan.go b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescan.go new file mode 100644 index 00000000..fc069c88 --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescan.go @@ -0,0 +1,203 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// ContainerImageScanApplyConfiguration represents an declarative configuration of the ContainerImageScan type for use +// with apply. +type ContainerImageScanApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Spec *ContainerImageScanSpecApplyConfiguration `json:"spec,omitempty"` + Status *ContainerImageScanStatusApplyConfiguration `json:"status,omitempty"` +} + +// ContainerImageScan constructs an declarative configuration of the ContainerImageScan type for use with +// apply. +func ContainerImageScan(name, namespace string) *ContainerImageScanApplyConfiguration { + b := &ContainerImageScanApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("ContainerImageScan") + b.WithAPIVersion("stas.statnett.no/v1alpha1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithKind(value string) *ContainerImageScanApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithAPIVersion(value string) *ContainerImageScanApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithName(value string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithGenerateName(value string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithNamespace(value string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithUID(value types.UID) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithResourceVersion(value string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithGeneration(value int64) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *ContainerImageScanApplyConfiguration) WithLabels(entries map[string]string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *ContainerImageScanApplyConfiguration) WithAnnotations(entries map[string]string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *ContainerImageScanApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *ContainerImageScanApplyConfiguration) WithFinalizers(values ...string) *ContainerImageScanApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *ContainerImageScanApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithSpec sets the Spec field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Spec field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithSpec(value *ContainerImageScanSpecApplyConfiguration) *ContainerImageScanApplyConfiguration { + b.Spec = value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *ContainerImageScanApplyConfiguration) WithStatus(value *ContainerImageScanStatusApplyConfiguration) *ContainerImageScanApplyConfiguration { + b.Status = value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanspec.go b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanspec.go new file mode 100644 index 00000000..38caf304 --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanspec.go @@ -0,0 +1,69 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + godigest "github.com/opencontainers/go-digest" +) + +// ContainerImageScanSpecApplyConfiguration represents an declarative configuration of the ContainerImageScanSpec type for use +// with apply. +type ContainerImageScanSpecApplyConfiguration struct { + ImageScanSpecApplyConfiguration `json:",inline"` + Tag *string `json:"tag,omitempty"` + Workload *WorkloadApplyConfiguration `json:"workload,omitempty"` +} + +// ContainerImageScanSpecApplyConfiguration constructs an declarative configuration of the ContainerImageScanSpec type for use with +// apply. +func ContainerImageScanSpec() *ContainerImageScanSpecApplyConfiguration { + return &ContainerImageScanSpecApplyConfiguration{} +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithName(value string) *ContainerImageScanSpecApplyConfiguration { + b.Name = &value + return b +} + +// WithDigest sets the Digest field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Digest field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithDigest(value godigest.Digest) *ContainerImageScanSpecApplyConfiguration { + b.Digest = &value + return b +} + +// WithMinSeverity sets the MinSeverity field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the MinSeverity field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithMinSeverity(value string) *ContainerImageScanSpecApplyConfiguration { + b.MinSeverity = &value + return b +} + +// WithIgnoreUnfixed sets the IgnoreUnfixed field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the IgnoreUnfixed field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithIgnoreUnfixed(value bool) *ContainerImageScanSpecApplyConfiguration { + b.IgnoreUnfixed = &value + return b +} + +// WithTag sets the Tag field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Tag field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithTag(value string) *ContainerImageScanSpecApplyConfiguration { + b.Tag = &value + return b +} + +// WithWorkload sets the Workload field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Workload field is set to the value of the last call. +func (b *ContainerImageScanSpecApplyConfiguration) WithWorkload(value *WorkloadApplyConfiguration) *ContainerImageScanSpecApplyConfiguration { + b.Workload = value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanstatus.go b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanstatus.go new file mode 100644 index 00000000..a2528041 --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/containerimagescanstatus.go @@ -0,0 +1,89 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" +) + +// ContainerImageScanStatusApplyConfiguration represents an declarative configuration of the ContainerImageScanStatus type for use +// with apply. +type ContainerImageScanStatusApplyConfiguration struct { + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` + LastScanJobUID *types.UID `json:"lastScanJobUID,omitempty"` + LastScanTime *v1.Time `json:"lastScanTime,omitempty"` + LastSuccessfulScanTime *v1.Time `json:"lastSuccessfulScanTime,omitempty"` + Conditions []v1.Condition `json:"conditions,omitempty"` + Vulnerabilities []VulnerabilityApplyConfiguration `json:"vulnerabilities,omitempty"` + VulnerabilitySummary *VulnerabilitySummaryApplyConfiguration `json:"vulnerabilitySummary,omitempty"` +} + +// ContainerImageScanStatusApplyConfiguration constructs an declarative configuration of the ContainerImageScanStatus type for use with +// apply. +func ContainerImageScanStatus() *ContainerImageScanStatusApplyConfiguration { + return &ContainerImageScanStatusApplyConfiguration{} +} + +// WithObservedGeneration sets the ObservedGeneration field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObservedGeneration field is set to the value of the last call. +func (b *ContainerImageScanStatusApplyConfiguration) WithObservedGeneration(value int64) *ContainerImageScanStatusApplyConfiguration { + b.ObservedGeneration = &value + return b +} + +// WithLastScanJobUID sets the LastScanJobUID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the LastScanJobUID field is set to the value of the last call. +func (b *ContainerImageScanStatusApplyConfiguration) WithLastScanJobUID(value types.UID) *ContainerImageScanStatusApplyConfiguration { + b.LastScanJobUID = &value + return b +} + +// WithLastScanTime sets the LastScanTime field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the LastScanTime field is set to the value of the last call. +func (b *ContainerImageScanStatusApplyConfiguration) WithLastScanTime(value v1.Time) *ContainerImageScanStatusApplyConfiguration { + b.LastScanTime = &value + return b +} + +// WithLastSuccessfulScanTime sets the LastSuccessfulScanTime field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the LastSuccessfulScanTime field is set to the value of the last call. +func (b *ContainerImageScanStatusApplyConfiguration) WithLastSuccessfulScanTime(value v1.Time) *ContainerImageScanStatusApplyConfiguration { + b.LastSuccessfulScanTime = &value + return b +} + +// WithConditions adds the given value to the Conditions field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Conditions field. +func (b *ContainerImageScanStatusApplyConfiguration) WithConditions(values ...v1.Condition) *ContainerImageScanStatusApplyConfiguration { + for i := range values { + b.Conditions = append(b.Conditions, values[i]) + } + return b +} + +// WithVulnerabilities adds the given value to the Vulnerabilities field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Vulnerabilities field. +func (b *ContainerImageScanStatusApplyConfiguration) WithVulnerabilities(values ...*VulnerabilityApplyConfiguration) *ContainerImageScanStatusApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithVulnerabilities") + } + b.Vulnerabilities = append(b.Vulnerabilities, *values[i]) + } + return b +} + +// WithVulnerabilitySummary sets the VulnerabilitySummary field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the VulnerabilitySummary field is set to the value of the last call. +func (b *ContainerImageScanStatusApplyConfiguration) WithVulnerabilitySummary(value *VulnerabilitySummaryApplyConfiguration) *ContainerImageScanStatusApplyConfiguration { + b.VulnerabilitySummary = value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/image.go b/internal/client/applyconfiguration/stas/v1alpha1/image.go new file mode 100644 index 00000000..a320f16b --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/image.go @@ -0,0 +1,36 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + godigest "github.com/opencontainers/go-digest" +) + +// ImageApplyConfiguration represents an declarative configuration of the Image type for use +// with apply. +type ImageApplyConfiguration struct { + Name *string `json:"name,omitempty"` + Digest *godigest.Digest `json:"digest,omitempty"` +} + +// ImageApplyConfiguration constructs an declarative configuration of the Image type for use with +// apply. +func Image() *ImageApplyConfiguration { + return &ImageApplyConfiguration{} +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ImageApplyConfiguration) WithName(value string) *ImageApplyConfiguration { + b.Name = &value + return b +} + +// WithDigest sets the Digest field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Digest field is set to the value of the last call. +func (b *ImageApplyConfiguration) WithDigest(value godigest.Digest) *ImageApplyConfiguration { + b.Digest = &value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/imagescanspec.go b/internal/client/applyconfiguration/stas/v1alpha1/imagescanspec.go new file mode 100644 index 00000000..8cc92bc5 --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/imagescanspec.go @@ -0,0 +1,52 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + godigest "github.com/opencontainers/go-digest" +) + +// ImageScanSpecApplyConfiguration represents an declarative configuration of the ImageScanSpec type for use +// with apply. +type ImageScanSpecApplyConfiguration struct { + ImageApplyConfiguration `json:",inline"` + ScanConfigApplyConfiguration `json:",inline"` +} + +// ImageScanSpecApplyConfiguration constructs an declarative configuration of the ImageScanSpec type for use with +// apply. +func ImageScanSpec() *ImageScanSpecApplyConfiguration { + return &ImageScanSpecApplyConfiguration{} +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ImageScanSpecApplyConfiguration) WithName(value string) *ImageScanSpecApplyConfiguration { + b.Name = &value + return b +} + +// WithDigest sets the Digest field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Digest field is set to the value of the last call. +func (b *ImageScanSpecApplyConfiguration) WithDigest(value godigest.Digest) *ImageScanSpecApplyConfiguration { + b.Digest = &value + return b +} + +// WithMinSeverity sets the MinSeverity field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the MinSeverity field is set to the value of the last call. +func (b *ImageScanSpecApplyConfiguration) WithMinSeverity(value string) *ImageScanSpecApplyConfiguration { + b.MinSeverity = &value + return b +} + +// WithIgnoreUnfixed sets the IgnoreUnfixed field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the IgnoreUnfixed field is set to the value of the last call. +func (b *ImageScanSpecApplyConfiguration) WithIgnoreUnfixed(value bool) *ImageScanSpecApplyConfiguration { + b.IgnoreUnfixed = &value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/scanconfig.go b/internal/client/applyconfiguration/stas/v1alpha1/scanconfig.go new file mode 100644 index 00000000..5094398c --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/scanconfig.go @@ -0,0 +1,32 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// ScanConfigApplyConfiguration represents an declarative configuration of the ScanConfig type for use +// with apply. +type ScanConfigApplyConfiguration struct { + MinSeverity *string `json:"minSeverity,omitempty"` + IgnoreUnfixed *bool `json:"ignoreUnfixed,omitempty"` +} + +// ScanConfigApplyConfiguration constructs an declarative configuration of the ScanConfig type for use with +// apply. +func ScanConfig() *ScanConfigApplyConfiguration { + return &ScanConfigApplyConfiguration{} +} + +// WithMinSeverity sets the MinSeverity field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the MinSeverity field is set to the value of the last call. +func (b *ScanConfigApplyConfiguration) WithMinSeverity(value string) *ScanConfigApplyConfiguration { + b.MinSeverity = &value + return b +} + +// WithIgnoreUnfixed sets the IgnoreUnfixed field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the IgnoreUnfixed field is set to the value of the last call. +func (b *ScanConfigApplyConfiguration) WithIgnoreUnfixed(value bool) *ScanConfigApplyConfiguration { + b.IgnoreUnfixed = &value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/vulnerability.go b/internal/client/applyconfiguration/stas/v1alpha1/vulnerability.go new file mode 100644 index 00000000..5f8ca33a --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/vulnerability.go @@ -0,0 +1,86 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// VulnerabilityApplyConfiguration represents an declarative configuration of the Vulnerability type for use +// with apply. +type VulnerabilityApplyConfiguration struct { + VulnerabilityID *string `json:"vulnerabilityID,omitempty"` + PkgName *string `json:"pkgName,omitempty"` + InstalledVersion *string `json:"installedVersion,omitempty"` + Severity *string `json:"severity,omitempty"` + PkgPath *string `json:"pkgPath,omitempty"` + FixedVersion *string `json:"fixedVersion,omitempty"` + Title *string `json:"title,omitempty"` + PrimaryURL *string `json:"primaryURL,omitempty"` +} + +// VulnerabilityApplyConfiguration constructs an declarative configuration of the Vulnerability type for use with +// apply. +func Vulnerability() *VulnerabilityApplyConfiguration { + return &VulnerabilityApplyConfiguration{} +} + +// WithVulnerabilityID sets the VulnerabilityID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the VulnerabilityID field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithVulnerabilityID(value string) *VulnerabilityApplyConfiguration { + b.VulnerabilityID = &value + return b +} + +// WithPkgName sets the PkgName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PkgName field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithPkgName(value string) *VulnerabilityApplyConfiguration { + b.PkgName = &value + return b +} + +// WithInstalledVersion sets the InstalledVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the InstalledVersion field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithInstalledVersion(value string) *VulnerabilityApplyConfiguration { + b.InstalledVersion = &value + return b +} + +// WithSeverity sets the Severity field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Severity field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithSeverity(value string) *VulnerabilityApplyConfiguration { + b.Severity = &value + return b +} + +// WithPkgPath sets the PkgPath field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PkgPath field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithPkgPath(value string) *VulnerabilityApplyConfiguration { + b.PkgPath = &value + return b +} + +// WithFixedVersion sets the FixedVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the FixedVersion field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithFixedVersion(value string) *VulnerabilityApplyConfiguration { + b.FixedVersion = &value + return b +} + +// WithTitle sets the Title field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Title field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithTitle(value string) *VulnerabilityApplyConfiguration { + b.Title = &value + return b +} + +// WithPrimaryURL sets the PrimaryURL field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PrimaryURL field is set to the value of the last call. +func (b *VulnerabilityApplyConfiguration) WithPrimaryURL(value string) *VulnerabilityApplyConfiguration { + b.PrimaryURL = &value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/vulnerabilitysummary.go b/internal/client/applyconfiguration/stas/v1alpha1/vulnerabilitysummary.go new file mode 100644 index 00000000..49a019fa --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/vulnerabilitysummary.go @@ -0,0 +1,47 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// VulnerabilitySummaryApplyConfiguration represents an declarative configuration of the VulnerabilitySummary type for use +// with apply. +type VulnerabilitySummaryApplyConfiguration struct { + SeverityCount map[string]int32 `json:"severityCount,omitempty"` + FixedCount *int32 `json:"fixedCount,omitempty"` + UnfixedCount *int32 `json:"unfixedCount,omitempty"` +} + +// VulnerabilitySummaryApplyConfiguration constructs an declarative configuration of the VulnerabilitySummary type for use with +// apply. +func VulnerabilitySummary() *VulnerabilitySummaryApplyConfiguration { + return &VulnerabilitySummaryApplyConfiguration{} +} + +// WithSeverityCount puts the entries into the SeverityCount field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the SeverityCount field, +// overwriting an existing map entries in SeverityCount field with the same key. +func (b *VulnerabilitySummaryApplyConfiguration) WithSeverityCount(entries map[string]int32) *VulnerabilitySummaryApplyConfiguration { + if b.SeverityCount == nil && len(entries) > 0 { + b.SeverityCount = make(map[string]int32, len(entries)) + } + for k, v := range entries { + b.SeverityCount[k] = v + } + return b +} + +// WithFixedCount sets the FixedCount field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the FixedCount field is set to the value of the last call. +func (b *VulnerabilitySummaryApplyConfiguration) WithFixedCount(value int32) *VulnerabilitySummaryApplyConfiguration { + b.FixedCount = &value + return b +} + +// WithUnfixedCount sets the UnfixedCount field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UnfixedCount field is set to the value of the last call. +func (b *VulnerabilitySummaryApplyConfiguration) WithUnfixedCount(value int32) *VulnerabilitySummaryApplyConfiguration { + b.UnfixedCount = &value + return b +} diff --git a/internal/client/applyconfiguration/stas/v1alpha1/workload.go b/internal/client/applyconfiguration/stas/v1alpha1/workload.go new file mode 100644 index 00000000..1f0c1c26 --- /dev/null +++ b/internal/client/applyconfiguration/stas/v1alpha1/workload.go @@ -0,0 +1,50 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// WorkloadApplyConfiguration represents an declarative configuration of the Workload type for use +// with apply. +type WorkloadApplyConfiguration struct { + Group *string `json:"group,omitempty"` + Kind *string `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + ContainerName *string `json:"containerName,omitempty"` +} + +// WorkloadApplyConfiguration constructs an declarative configuration of the Workload type for use with +// apply. +func Workload() *WorkloadApplyConfiguration { + return &WorkloadApplyConfiguration{} +} + +// WithGroup sets the Group field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Group field is set to the value of the last call. +func (b *WorkloadApplyConfiguration) WithGroup(value string) *WorkloadApplyConfiguration { + b.Group = &value + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *WorkloadApplyConfiguration) WithKind(value string) *WorkloadApplyConfiguration { + b.Kind = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *WorkloadApplyConfiguration) WithName(value string) *WorkloadApplyConfiguration { + b.Name = &value + return b +} + +// WithContainerName sets the ContainerName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ContainerName field is set to the value of the last call. +func (b *WorkloadApplyConfiguration) WithContainerName(value string) *WorkloadApplyConfiguration { + b.ContainerName = &value + return b +} diff --git a/internal/client/applyconfiguration/utils.go b/internal/client/applyconfiguration/utils.go new file mode 100644 index 00000000..cc014afe --- /dev/null +++ b/internal/client/applyconfiguration/utils.go @@ -0,0 +1,37 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package applyconfiguration + +import ( + v1alpha1 "github.com/statnett/image-scanner-operator/api/stas/v1alpha1" + stasv1alpha1 "github.com/statnett/image-scanner-operator/internal/client/applyconfiguration/stas/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no +// apply configuration type exists for the given GroupVersionKind. +func ForKind(kind schema.GroupVersionKind) interface{} { + switch kind { + // Group=stas.statnett.no, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithKind("ContainerImageScan"): + return &stasv1alpha1.ContainerImageScanApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("ContainerImageScanSpec"): + return &stasv1alpha1.ContainerImageScanSpecApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("ContainerImageScanStatus"): + return &stasv1alpha1.ContainerImageScanStatusApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("Image"): + return &stasv1alpha1.ImageApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("ImageScanSpec"): + return &stasv1alpha1.ImageScanSpecApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("ScanConfig"): + return &stasv1alpha1.ScanConfigApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("Vulnerability"): + return &stasv1alpha1.VulnerabilityApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("VulnerabilitySummary"): + return &stasv1alpha1.VulnerabilitySummaryApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("Workload"): + return &stasv1alpha1.WorkloadApplyConfiguration{} + + } + return nil +} From 0d31efdfeaca44e5bcbb5ce163038cdf098e1fa9 Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Wed, 25 Oct 2023 23:37:07 +0200 Subject: [PATCH 2/2] fix failing test --- .../controller/stas/testdata/scan-job/expected-scan-job.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/stas/testdata/scan-job/expected-scan-job.yaml b/internal/controller/stas/testdata/scan-job/expected-scan-job.yaml index b50ed282..0e8625d9 100644 --- a/internal/controller/stas/testdata/scan-job/expected-scan-job.yaml +++ b/internal/controller/stas/testdata/scan-job/expected-scan-job.yaml @@ -12,7 +12,7 @@ metadata: workload.statnett.no/name: echo workload.statnett.no/namespace: replica-set namespace: image-scanner - name: echo-6bdfc76c56-8ae43-738e6 + name: echo-6bdfc76c56-8ae43-38618 spec: activeDeadlineSeconds: 3600 # 1 hour backoffLimit: 3