Add DeepCopy generation target to Makefile

Change-Id: I974f8472f2ad8231a6612849f1bc73895c96ef81
Closes: #384
This commit is contained in:
Dmitry Ukov 2020-11-02 16:39:50 +04:00
parent 334ff8041b
commit 3acd9ab8f5
4 changed files with 76 additions and 11 deletions

View File

@ -5,6 +5,12 @@ GIT_MODULE ?= opendev.org/airship/airshipctl/pkg/version
GO_FLAGS := -ldflags '-extldflags "-static"' -tags=netgo -trimpath
GO_FLAGS += -ldflags "-X ${GIT_MODULE}.gitVersion=${GIT_VERSION}"
# 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
BINDIR := bin
EXECUTABLE_CLI := airshipctl
@ -241,3 +247,24 @@ check-copyright:
.PHONY: validate-docs
validate-docs:
@./tools/validate_docs
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="tools/license_go.txt" paths="./..."
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

View File

@ -18,6 +18,18 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +kubebuilder:object:root=true
// BootConfiguration structure is inherited from apimachinery TypeMeta and ObjectMeta and is a top level
// configuration structure for the bootstrap container
type BootConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
BootstrapContainer BootstrapContainer `json:"bootstrapContainer"`
EphemeralCluster EphemeralCluster `json:"ephemeralCluster"`
}
// EphemeralCluster structure contains the data for the ephemeral cluster
type EphemeralCluster struct {
BootstrapCommand string `json:"bootstrapCommand,omitempty"`
@ -32,16 +44,6 @@ type BootstrapContainer struct {
Kubeconfig string `json:"kubeconfig,omitempty"`
}
// BootConfiguration structure is inherited from apimachinery TypeMeta and ObjectMeta and is a top level
// configuration structure for the bootstrap container
type BootConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
BootstrapContainer BootstrapContainer `json:"bootstrapContainer"`
EphemeralCluster EphemeralCluster `json:"ephemeralCluster"`
}
// DefaultBootConfiguration can be used to safely unmarshal BootConfiguration object without nil pointers
func DefaultBootConfiguration() *BootConfiguration {
return &BootConfiguration{}

View File

@ -1,5 +1,19 @@
// +build !ignore_autogenerated
/*
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
https://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.
*/
// Code generated by controller-gen. DO NOT EDIT.
package v1alpha1
@ -217,6 +231,13 @@ func (in *Clusterctl) DeepCopyInto(out *Clusterctl) {
(*out)[key] = val
}
}
if in.ImageMetas != nil {
in, out := &in.ImageMetas, &out.ImageMetas
*out = make(map[string]ImageMeta, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Clusterctl.
@ -302,6 +323,21 @@ func (in *ImageConfiguration) DeepCopyObject() runtime.Object {
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ImageMeta) DeepCopyInto(out *ImageMeta) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageMeta.
func (in *ImageMeta) DeepCopy() *ImageMeta {
if in == nil {
return nil
}
out := new(ImageMeta)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *InitOptions) DeepCopyInto(out *InitOptions) {
*out = *in

View File

@ -18,7 +18,7 @@ declare FILES_MISSING_COPYRIGHT=()
check_license() {
ext=$1
# skipping license for testdata and manifests folders
FILES=$(find -L . -name "*.${ext}" | grep -vE "(testdata|manifests|zz_generated)")
FILES=$(find -L . -name "*.${ext}" | grep -vE "(testdata|manifests)")
for each in $FILES
do