diff --git a/Makefile b/Makefile index d96153db..cb573414 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PROJECT_DIR:=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) OUT_DIR:=out export ISTIO_VERSION ?= 1.23.0 +CONTROLLER_TOOLS_VERSION ?= v0.16.4 ## Required tooling. ## Needs to be defined early so that any target depending on given binary can resolve it when not present. @@ -13,12 +14,18 @@ PROTOC := $(LOCALBIN)/protoc PROTOC_GEN_GO := $(LOCALBIN)/protoc-gen-go PROTOC_GEN_GRPC := $(LOCALBIN)/protoc-gen-go-grpc PROTOC_GEN_DEEPCOPY := $(LOCALBIN)/protoc-gen-golang-deepcopy +CONTROLLER_GEN := $(LOCALBIN)/controller-gen PROTOBUF_API_DIR := $(PROJECT_DIR)/api/proto/federation PROTOBUF_API_SRC := $(shell find $(PROTOBUF_API_DIR) -type f -name "*.proto") API_GEN_DIR=$(PROJECT_DIR)/internal/api PROTOBUF_GEN := $(shell find $(API_GEN_DIR) -type f -name "*.go") +CRD_SRC_DIR := $(PROJECT_DIR)/api/v1alpha1 +CRD_SRC := $(shell find $(CRD_SRC_DIR) -type f -name "*.go") +CRD_GEN_DIR := $(PROJECT_DIR)/chart/crds +CRD_GEN := $(shell find $(CRD_GEN_DIR) -type f -name "*.yaml") + .PHONY: default default: build add-license fix-imports test @@ -36,7 +43,7 @@ deps: ## Downloads required dependencies EXTRA_BUILD_ARGS?= .PHONY: build -build: deps $(PROTOBUF_GEN) ## Builds the project +build: deps $(PROTOBUF_GEN) $(DEEP_COPY_GEN) $(CRD_GEN) ## Builds the project go build -C $(PROJECT_DIR)/cmd/federation-controller -o $(PROJECT_DIR)/$(OUT_DIR)/federation-controller $(EXTRA_BUILD_ARGS) .PHONY: test @@ -123,8 +130,11 @@ $(PROTOC_GEN_DEEPCOPY): $(KIND): @GOBIN=$(LOCALBIN) go install -mod=readonly sigs.k8s.io/kind@v0.26.0 +$(CONTROLLER_GEN): + GOBIN=$(LOCALBIN) go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) + .PHONY: clean -clean: +clean: @rm -rf $(LOCALBIN) $(PROJECT_DIR)/$(OUT_DIR) ##@ Code Gen @@ -132,34 +142,23 @@ clean: $(PROTOBUF_GEN): $(PROTOBUF_API_SRC) $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_GRPC) $(PROTOC_GEN_DEEPCOPY) ## Generates Go files from protobuf-based API files @PATH=$(LOCALBIN):$$PATH $(PROTOC) --proto_path=$(PROTOBUF_API_DIR) --go_out=$(API_GEN_DIR) --go-grpc_out=$(API_GEN_DIR) --golang-deepcopy_out=:$(API_GEN_DIR) $(PROTOBUF_API_DIR)/**/*.proto +$(CRD_GEN): $(CRD_SRC) $(CONTROLLER_GEN) ## Generates CRDs and DeepCopy method implementations. + $(CONTROLLER_GEN) paths="$(CRD_SRC_DIR)/..." \ + crd output:crd:artifacts:config="$(CRD_GEN_DIR)" \ + object:headerFile="$(LICENSE_FILE)" + .PHONY: fix-imports fix-imports: $(GOIMPORTS) ## Fixes imports $(GOIMPORTS) -local "github.com/openshift-service-mesh/federation" -w $(PROJECT_DIR)/ -LICENSE_FILE := /tmp/license.txt +LICENSE_FILE := $(PROJECT_DIR)/hack/boilerplate.go.txt GO_FILES := $(shell find $(PROJECT_DIR)/ -name '*.go') .PHONY: add-license add-license: ## Adds license to all Golang files - @echo "// Copyright Red Hat, Inc." > $(LICENSE_FILE) - @echo "//" >> $(LICENSE_FILE) - @echo "// Licensed under the Apache License, Version 2.0 (the "License");" >> $(LICENSE_FILE) - @echo "// you may not use this file except in compliance with the License." >> $(LICENSE_FILE) - @echo "// You may obtain a copy of the License at" >> $(LICENSE_FILE) - @echo "//" >> $(LICENSE_FILE) - @echo "// http://www.apache.org/licenses/LICENSE-2.0" >> $(LICENSE_FILE) - @echo "//" >> $(LICENSE_FILE) - @echo "// Unless required by applicable law or agreed to in writing, software" >> $(LICENSE_FILE) - @echo "// distributed under the License is distributed on an "AS IS" BASIS," >> $(LICENSE_FILE) - @echo "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $(LICENSE_FILE) - @echo "// See the License for the specific language governing permissions and" >> $(LICENSE_FILE) - @echo "// limitations under the License." >> $(LICENSE_FILE) - @echo "" >> $(LICENSE_FILE) - @for file in $(GO_FILES); do \ if ! grep -q "Licensed under the Apache License" $$file; then \ echo "Adding license to $$file"; \ cat $(LICENSE_FILE) $$file > temp && mv temp $$file; \ fi \ done - @rm -f $(LICENSE_FILE) diff --git a/PROJECT b/PROJECT new file mode 100644 index 00000000..2045b22e --- /dev/null +++ b/PROJECT @@ -0,0 +1,19 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html +domain: openshift-service-mesh.io +layout: +- go.kubebuilder.io/v4 +projectName: federation +repo: github.com/openshift-service-mesh/federation +resources: +- api: + crdVersion: v1 + controller: true + domain: openshift-service-mesh.io + group: federation + kind: MeshFederation + path: github.com/openshift-service-mesh/federation/api/v1alpha1 + version: v1alpha1 +version: "3" diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go new file mode 100644 index 00000000..6a08306f --- /dev/null +++ b/api/v1alpha1/groupversion_info.go @@ -0,0 +1,34 @@ +// Copyright Red Hat, Inc. +// +// 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 v1alpha1 contains API Schema definitions for the federation v1alpha1 API group. +// +kubebuilder:object:generate=true +// +groupName=federation.openshift-service-mesh.io +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects. + GroupVersion = schema.GroupVersion{Group: "federation.openshift-service-mesh.io", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme. + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/api/v1alpha1/meshfederation_types.go b/api/v1alpha1/meshfederation_types.go new file mode 100644 index 00000000..f4c0121f --- /dev/null +++ b/api/v1alpha1/meshfederation_types.go @@ -0,0 +1,63 @@ +// Copyright Red Hat, Inc. +// +// 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// MeshFederationSpec defines the desired state of MeshFederation. +type MeshFederationSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of MeshFederation. Edit meshfederation_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// MeshFederationStatus defines the observed state of MeshFederation. +type MeshFederationStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster + +// MeshFederation is the Schema for the meshfederations API. +type MeshFederation struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec MeshFederationSpec `json:"spec,omitempty"` + Status MeshFederationStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// MeshFederationList contains a list of MeshFederation. +type MeshFederationList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []MeshFederation `json:"items"` +} + +func init() { + SchemeBuilder.Register(&MeshFederation{}, &MeshFederationList{}) +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000..e64c648f --- /dev/null +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,112 @@ +//go:build !ignore_autogenerated + +// Copyright Red Hat, Inc. +// +// 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. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MeshFederation) DeepCopyInto(out *MeshFederation) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MeshFederation. +func (in *MeshFederation) DeepCopy() *MeshFederation { + if in == nil { + return nil + } + out := new(MeshFederation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MeshFederation) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MeshFederationList) DeepCopyInto(out *MeshFederationList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MeshFederation, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MeshFederationList. +func (in *MeshFederationList) DeepCopy() *MeshFederationList { + if in == nil { + return nil + } + out := new(MeshFederationList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MeshFederationList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MeshFederationSpec) DeepCopyInto(out *MeshFederationSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MeshFederationSpec. +func (in *MeshFederationSpec) DeepCopy() *MeshFederationSpec { + if in == nil { + return nil + } + out := new(MeshFederationSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MeshFederationStatus) DeepCopyInto(out *MeshFederationStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MeshFederationStatus. +func (in *MeshFederationStatus) DeepCopy() *MeshFederationStatus { + if in == nil { + return nil + } + out := new(MeshFederationStatus) + in.DeepCopyInto(out) + return out +} diff --git a/chart/crds/federation.openshift-service-mesh.io_meshfederations.yaml b/chart/crds/federation.openshift-service-mesh.io_meshfederations.yaml new file mode 100644 index 00000000..8428ea76 --- /dev/null +++ b/chart/crds/federation.openshift-service-mesh.io_meshfederations.yaml @@ -0,0 +1,54 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.4 + name: meshfederations.federation.openshift-service-mesh.io +spec: + group: federation.openshift-service-mesh.io + names: + kind: MeshFederation + listKind: MeshFederationList + plural: meshfederations + singular: meshfederation + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: MeshFederation is the Schema for the meshfederations API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: MeshFederationSpec defines the desired state of MeshFederation. + properties: + foo: + description: Foo is an example field of MeshFederation. Edit meshfederation_types.go + to remove/update + type: string + type: object + status: + description: MeshFederationStatus defines the observed state of MeshFederation. + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt new file mode 100644 index 00000000..67f551e4 --- /dev/null +++ b/hack/boilerplate.go.txt @@ -0,0 +1,14 @@ +// Copyright Red Hat, Inc. +// +// 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. +