-
Notifications
You must be signed in to change notification settings - Fork 8
feat(build): introduces controller-gen scaffolding #121
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
Merged
openshift-merge-bot
merged 9 commits into
openshift-service-mesh:master
from
eoinfennessy:introduce-kubebuilder
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1e78ecf
scaffold MeshFederation API and add codegen tools
eoinfennessy 5caebf7
fix license headers
eoinfennessy dab33eb
add PROJECT_DIR to path of license file
eoinfennessy 082336a
use -mod=readonly when installing controller-gen
eoinfennessy 5f97ddc
add manifests target to generate CRDs
eoinfennessy 593202f
change project domain to openshift-service-mesh.io
eoinfennessy 72e711b
Run make manifests
eoinfennessy 24ec1d5
Generate CRDs and DeepCopy methods on src file changes
eoinfennessy 6da6672
Combine targets to generate CRDs and DeepCopy methods
eoinfennessy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,43 +130,35 @@ $(PROTOC_GEN_DEEPCOPY): | |
$(KIND): | ||
@GOBIN=$(LOCALBIN) go install -mod=readonly sigs.k8s.io/[email protected] | ||
|
||
$(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 | ||
|
||
$(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 | ||
bartoszmajsak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
chart/crds/federation.openshift-service-mesh.io_meshfederations.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.