From a143a6cd59177f1f72e2f173bc5cfdbe8d723157 Mon Sep 17 00:00:00 2001 From: Dinar Valeev Date: Mon, 8 Mar 2021 19:57:24 +0100 Subject: [PATCH] Generate CRD with controller-gen Signed-off-by: Dinar Valeev --- Makefile | 22 ++++++++++ .../contributing/crd-source/crd-manifest.yaml | 40 +++++++++++++++++-- endpoint/endpoint.go | 5 +++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0f2b274e8..1818baac1 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,23 @@ cover: cover-html: cover go tool cover -html cover.out +# 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.5.0 ;\ + rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ + } +CONTROLLER_GEN=$(GOBIN)/controller-gen +else +CONTROLLER_GEN=$(shell which controller-gen) +endif + .PHONY: go-lint # Run the golangci-lint tool @@ -51,6 +68,11 @@ licensecheck: # Run all the linters lint: licensecheck go-lint +.PHONY: crd + +# generates CRD using controller-gen +crd: controller-gen + ${CONTROLLER_GEN} crd:crdVersions=v1beta1 paths="./endpoint/..." output:crd:stdout > docs/contributing/crd-source/crd-manifest.yaml # The verify target runs tasks similar to the CI tasks, but without code coverage .PHONY: verify test diff --git a/docs/contributing/crd-source/crd-manifest.yaml b/docs/contributing/crd-source/crd-manifest.yaml index 842928690..ea801b11b 100644 --- a/docs/contributing/crd-source/crd-manifest.yaml +++ b/docs/contributing/crd-source/crd-manifest.yaml @@ -1,16 +1,19 @@ + +--- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.5.0 creationTimestamp: null - labels: - api: externaldns - kubebuilder.k8s.io: 1.0.0 name: dnsendpoints.externaldns.k8s.io spec: group: externaldns.k8s.io names: kind: DNSEndpoint + listKind: DNSEndpointList plural: dnsendpoints + singular: dnsendpoint scope: Namespaced subresources: status: {} @@ -18,35 +21,51 @@ spec: openAPIV3Schema: 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: DNSEndpointSpec defines the desired state of DNSEndpoint properties: endpoints: items: + description: Endpoint is a high-level way of a connection between a service and an IP properties: dnsName: + description: The hostname of the DNS record type: string labels: + additionalProperties: + type: string + description: Labels stores labels defined for the Endpoint type: object providerSpecific: + description: ProviderSpecific stores provider specific config items: + description: ProviderSpecificProperty holds the name and value of a configuration which is specific to individual DNS providers properties: - name: + name: type: string value: type: string type: object type: array recordTTL: + description: TTL for the record format: int64 type: integer recordType: + description: RecordType type of record, e.g. CNAME, A, SRV, TXT etc + type: string + setIdentifier: + description: Identifier to distinguish multiple records with the same name and type (e.g. Route53 records with routing policies other than 'simple') type: string targets: + description: The targets the DNS record points to items: type: string type: array @@ -54,9 +73,22 @@ spec: type: array type: object status: + description: DNSEndpointStatus defines the observed state of DNSEndpoint properties: observedGeneration: + description: The generation observed by the external-dns controller. format: int64 type: integer type: object + type: object version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 07bd3ea4b..7d7be8e00 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -213,8 +213,12 @@ type DNSEndpointStatus struct { // DNSEndpoint is a contract that a user-specified CRD must implement to be used as a source for external-dns. // The user-specified CRD should also have the status sub-resource. // +k8s:openapi-gen=true +// +groupName=externaldns.k8s.io // +kubebuilder:resource:path=dnsendpoints +// +kubebuilder:object:root=true // +kubebuilder:subresource:status +// +versionName=v1alpha1 + type DNSEndpoint struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -223,6 +227,7 @@ type DNSEndpoint struct { Status DNSEndpointStatus `json:"status,omitempty"` } +// +kubebuilder:object:root=true // DNSEndpointList is a list of DNSEndpoint objects type DNSEndpointList struct { metav1.TypeMeta `json:",inline"`