Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generate applyconfigurations for API #668

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions api/stas/v1alpha1/containerimagescan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -110,6 +111,7 @@ type ContainerImageScanStatus struct {
VulnerabilitySummary *VulnerabilitySummary `json:"vulnerabilitySummary,omitempty"`
}

//+genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName={cis}
Expand Down
5 changes: 5 additions & 0 deletions api/stas/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions api/stas/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion api/stas/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)
46 changes: 46 additions & 0 deletions internal/client/applyconfiguration/internal/internal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading