Skip to content

api: Generate CRDs from APIs #456

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
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
#define the GO_BUILD_ARGS if you need to pass additional arguments to the go build
GO_BUILD_ARGS?=

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.9.2

## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

# Reset branch name if this a Travis CI environment
ifneq ($(strip $(TRAVIS_BRANCH)),)
GIT_BRANCH:=${TRAVIS_BRANCH}
Expand All @@ -28,7 +39,7 @@ endif

.PHONY: print-global-variables

# Build the controler executable for use in docker image build
# Build the controller executable for use in docker image build
mcad-controller: init generate-code
ifeq ($(strip $(GO_BUILD_ARGS)),)
$(info Compiling controller)
Expand Down Expand Up @@ -60,6 +71,15 @@ verify-tag-name: print-global-variables
# Check for invalid tag name
t=${TAG} && [ $${#t} -le 128 ] || { echo "Target name $$t has 128 or more chars"; false; }

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: manifests
manifests: controller-gen ## Generate CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd:allowDangerousTypes=true paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases

generate-code: pkg/apis/controller/v1beta1/zz_generated.deepcopy.go

pkg/apis/controller/v1beta1/zz_generated.deepcopy.go: ${BIN_DIR}/deepcopy-gen
Expand Down Expand Up @@ -139,18 +159,17 @@ clean:
#CRD file maintenance rules
DEPLOYMENT_CRD_DIR=deployment/mcad-controller/crds
CRD_BASE_DIR=config/crd/bases
MCAD_CRDS= ${DEPLOYMENT_CRD_DIR}/ibm.com_quotasubtree-v1.yaml \
MCAD_CRDS= ${DEPLOYMENT_CRD_DIR}/ibm.com_quotasubtrees.yaml \
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_appwrappers.yaml \
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_queuejobs.yaml \
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_schedulingspecs.yaml

update-deployment-crds: ${MCAD_CRDS}

${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_schedulingspecs.yaml : ${CRD_BASE_DIR}/mcad.ibm.com_schedulingspecs.yaml
${DEPLOYMENT_CRD_DIR}/ibm.com_quotasubtrees.yaml : ${CRD_BASE_DIR}/ibm.com_quotasubtrees.yaml
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_appwrappers.yaml : ${CRD_BASE_DIR}/mcad.ibm.com_appwrappers.yaml
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_queuejobs.yaml : ${CRD_BASE_DIR}/mcad.ibm.com_queuejobs.yaml
${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_schedulingspecs.yaml : ${CRD_BASE_DIR}/mcad.ibm.com_schedulingspecs.yaml


$(DEPLOYMENT_CRD_DIR)/%: ${CRD_BASE_DIR}/%
cp $< $@
cp $< $@
62 changes: 0 additions & 62 deletions config/crd/bases/ibm.com_quotasubtree-v1.yaml

This file was deleted.

122 changes: 122 additions & 0 deletions config/crd/bases/ibm.com_quotasubtrees.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: quotasubtrees.ibm.com
spec:
group: ibm.com
names:
kind: QuotaSubtree
listKind: QuotaSubtreeList
plural: quotasubtrees
singular: quotasubtree
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: QuotaSubtree is a specification for a quota subtree resource
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: QuotaSubtreeSpec is the spec for a resource plan
properties:
children:
items:
description: Child is the spec for a QuotaSubtree resource
properties:
name:
type: string
namespace:
type: string
path:
type: string
quotas:
description: Quota is the spec for a QuotaSubtree resource
properties:
disabled:
type: boolean
hardLimit:
type: boolean
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
type: object
type: array
parent:
type: string
parentNamespace:
type: string
type: object
status:
description: QuotaSubtreeStatus is the status for a QuotaSubtree resource
properties:
children:
items:
description: ResourceAllocation is the spec for the child status
properties:
allocated:
description: ResourceAllocationStatus is the spec for the child
resource usage
properties:
requests:
additionalProperties:
type: string
type: object
type: object
name:
type: string
namespace:
type: string
path:
type: string
type: object
type: array
totalAllocation:
description: ResourceAllocation is the spec for the child status
properties:
allocated:
description: ResourceAllocationStatus is the spec for the child
resource usage
properties:
requests:
additionalProperties:
type: string
type: object
type: object
name:
type: string
namespace:
type: string
path:
type: string
type: object
required:
- children
- totalAllocation
type: object
required:
- spec
type: object
served: true
storage: true
Loading