Skip to content

Commit

Permalink
feat: crd generate crds (#1389)
Browse files Browse the repository at this point in the history
Signed-off-by: huiwq1990 <huiwq1990@163.com>
  • Loading branch information
huiwq1990 authored Apr 21, 2023
1 parent 4356d43 commit a65b31c
Show file tree
Hide file tree
Showing 12 changed files with 1,328 additions and 1,260 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Verify Code
run: make verify

Expand Down
42 changes: 38 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ IMAGE_REPO ?= openyurt
IMAGE_TAG ?= $(shell git describe --abbrev=0 --tags)
GIT_COMMIT = $(shell git rev-parse HEAD)
ENABLE_AUTONOMY_TESTS ?=true
CRD_OPTIONS ?= "crd:crdVersions=v1"
CRD_OPTIONS ?= "crd:crdVersions=v1,maxDescLen=1000"
BUILD_KUSTOMIZE ?= _output/manifest
GOPROXY ?= $(shell go env GOPROXY)

Expand Down Expand Up @@ -51,6 +51,17 @@ ifneq (${https_proxy},)
DOCKER_BUILD_ARGS += --build-arg https_proxy='${https_proxy}'
endif

LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

KUSTOMIZE_VERSION ?= v4.5.7
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize

KUBECTL_VERSION ?= v1.22.3
KUBECTL ?= $(LOCALBIN)/kubectl

.PHONY: clean all build test

all: test build
Expand All @@ -68,7 +79,10 @@ clean:
-rm -Rf _output

# verify will verify the code.
verify: verify-mod verify-license
verify: verify-mod verify-license verify_manifests

verify_manifests:
hack/make-rules/verify_manifests.sh

# verify-license will check if license has been added to files.
verify-license:
Expand Down Expand Up @@ -155,10 +169,10 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
# hack/make-rule/generate_openapi.sh // TODO by kadisi
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/..."

manifests: generate ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
manifests: kustomize kubectl generate ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
rm -rf $(BUILD_KUSTOMIZE)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=role webhook paths="./pkg/..." output:crd:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/crd output:rbac:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/rbac output:webhook:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/webhook
hack/make-rules/kustomize_to_chart.sh --crd $(BUILD_KUSTOMIZE)/auto_generate/crd --webhook $(BUILD_KUSTOMIZE)/auto_generate/webhook --rbac $(BUILD_KUSTOMIZE)/auto_generate/rbac --output $(BUILD_KUSTOMIZE)/kustomize --templateDir charts/openyurt/templates
hack/make-rules/kustomize_to_chart.sh --crd $(BUILD_KUSTOMIZE)/auto_generate/crd --webhook $(BUILD_KUSTOMIZE)/auto_generate/webhook --rbac $(BUILD_KUSTOMIZE)/auto_generate/rbac --output $(BUILD_KUSTOMIZE)/kustomize --chartDir charts/openyurt


# newcontroller
Expand All @@ -176,6 +190,26 @@ else
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
endif

.PHONY: kubectl
kubectl: $(KUBECTL) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUBECTL): $(LOCALBIN)
@if test -x $(LOCALBIN)/kubectl && ! $(LOCALBIN)/kubectl version | grep -q $(KUBECTL_VERSION); then \
echo "$(LOCALBIN)/kubectl version is not expected $(KUBECTL_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kubectl; \
fi
test -s $(LOCALBIN)/kubectl || curl https://storage.googleapis.com/kubernetes-release/release/v1.22.3/bin/$(shell go env GOOS)/$(shell go env GOARCH)/kubectl -o $(KUBECTL)
chmod +x $(KUBECTL)

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
name: gateways.raven.openyurt.io
spec:
group: raven.openyurt.io
names:
categories:
- all
kind: Gateway
listKind: GatewayList
plural: gateways
shortNames:
- gw
singular: gateway
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.activeEndpoint.nodeName
name: ActiveEndpoint
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Gateway is the Schema for the gateways 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: GatewaySpec defines the desired state of Gateway
properties:
endpoints:
description: TODO add a field to configure using vxlan or host-gw
for inner gateway communication? Endpoints is a list of available
Endpoint.
items:
description: Endpoint stores all essential data for establishing
the VPN tunnel. TODO add priority field?
properties:
config:
additionalProperties:
type: string
type: object
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
publicIP:
type: string
underNAT:
type: boolean
required:
- nodeName
type: object
type: array
exposeType:
description: ExposeType determines how the Gateway is exposed.
type: string
nodeSelector:
description: NodeSelector is a label query over nodes that managed
by the gateway. The nodes in the same gateway should share same
layer 3 network.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
required:
- endpoints
type: object
status:
description: GatewayStatus defines the observed state of Gateway
properties:
activeEndpoint:
description: ActiveEndpoint is the reference of the active endpoint.
properties:
config:
additionalProperties:
type: string
type: object
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
publicIP:
type: string
underNAT:
type: boolean
required:
- nodeName
type: object
nodes:
description: Nodes contains all information of nodes managed by Gateway.
items:
description: NodeInfo stores information of node managed by Gateway.
properties:
nodeName:
type: string
privateIP:
type: string
subnets:
items:
type: string
type: array
required:
- nodeName
- privateIP
- subnets
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit a65b31c

Please sign in to comment.