Skip to content

Commit 4b863f7

Browse files
Copying MCAD CRDs in Kustomize config instead of referencing them (#357)
* copying mcad crds in kustomize config instead of referencing them * addressing feedback * build: split crds into their own files * refactor: isntall yq if not exists * updating kustomization.yaml and verify_generated_files workflow * remove restore * adding crds * update check_yq target * Update Makefile * Update Makefile * Update Makefile * commenting out lines --------- Co-authored-by: Dimitri Saridakis <[email protected]>
1 parent 61ebcde commit 4b863f7

7 files changed

+1030
-7
lines changed

.github/workflows/verify_generated_files.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ on:
77
- '**.go'
88
- '**go.mod'
99
- '**go.sum'
10+
- 'config/**'
1011
tags-ignore:
1112
- 'v*'
1213
pull_request:
1314
paths:
1415
- '**.go'
1516
- '**go.mod'
1617
- '**go.sum'
18+
- 'config/**'
1719
jobs:
1820
verify-imports:
1921
runs-on: ubuntu-latest

Makefile

+34-5
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ defaults:
146146

147147
gofmt -w $(DEFAULTS_TEST_FILE)
148148

149+
# this encounters sed issues on MacOS, quick fix is to use gsed or to escape the parentheses i.e. \( \)
149150
.PHONY: manifests
150-
manifests: controller-gen ## Generate RBAC objects.
151+
manifests: controller-gen kustomize ## Generate RBAC objects.
151152
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..."
153+
# $(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
154+
# $(KUSTOMIZE) build config/crd/mcad > config/crd/mcad.yaml && make split_yaml FILE=config/crd/mcad.yaml
152155

153156
.PHONY: fmt
154157
fmt: ## Run go fmt against code.
@@ -192,19 +195,16 @@ endif
192195

193196
.PHONY: install
194197
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
195-
$(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
196198
$(KUSTOMIZE) build config/crd | kubectl apply -f -
197199
git restore config/*
198200

199201
.PHONY: uninstall
200202
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
201-
$(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
202203
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
203204
git restore config/*
204205

205206
.PHONY: deploy
206207
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
207-
$(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
208208
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
209209
$(KUSTOMIZE) build config/${ENV} | kubectl apply -f -
210210
git restore config/*
@@ -224,6 +224,7 @@ $(LOCALBIN):
224224

225225
## Tool Binaries
226226
KUSTOMIZE ?= $(LOCALBIN)/kustomize
227+
YQ ?= $(LOCALBIN)/yq
227228
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
228229
ENVTEST ?= $(LOCALBIN)/setup-envtest
229230
OPENSHIFT-GOIMPORTS ?= $(LOCALBIN)/openshift-goimports
@@ -284,7 +285,6 @@ validate-bundle: install-operator-sdk
284285
.PHONY: bundle
285286
bundle: defaults manifests kustomize install-operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
286287
$(OPERATOR_SDK) generate kustomize manifests -q
287-
$(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
288288
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
289289
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/metadata/annotations/containerImage", "value": "$(IMG)" }]' --kind ClusterServiceVersion
290290
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
@@ -388,3 +388,32 @@ verify-imports: openshift-goimports ## Run import verifications.
388388
.PHONY: scorecard-bundle
389389
scorecard-bundle: install-operator-sdk ## Run scorecard tests on bundle image.
390390
$(OPERATOR_SDK) scorecard bundle
391+
392+
393+
FILE ?= input.yaml # Default value, it isn't a file, but the make cmds fill hang for longer without it
394+
temp_dir := temp_split
395+
output_dir := 'config/crd/'
396+
397+
.PHONY: check_yq
398+
check_yq:
399+
@command -v wget >/dev/null 2>&1 || (echo "Installing wget..."; apt-get install -y wget)
400+
@command -v $(YQ) >/dev/null 2>&1 || (echo "Installing yq..."; wget https://github.com/mikefarah/yq/releases/download/v4.2.0/yq_linux_amd64.tar.gz -O - |\
401+
tar xz && mv yq_linux_amd64 $(YQ))
402+
403+
# this works on a MacOS by replacing awk with gawk
404+
.PHONY: split_yaml
405+
split_yaml:
406+
@$(MAKE) check_yq
407+
@mkdir -p $(temp_dir)
408+
@awk '/apiVersion: /{if (x>0) close("$(temp_dir)/section_" x ".yaml"); x++}{print > "$(temp_dir)/section_"x".yaml"}' $(FILE)
409+
@$(MAKE) process_sections
410+
411+
.PHONY: process_sections
412+
process_sections:
413+
@mkdir -p $(output_dir)
414+
@for section_file in $(temp_dir)/section_*; do \
415+
metadata_name=$$(YQ e '.metadata.name' $$section_file); \
416+
file_name=$$(echo $$metadata_name | awk -F'.' '{print $$2"."$$3"_"$$1".yaml"}'); \
417+
mv $$section_file $(output_dir)/$$file_name; \
418+
done
419+
@rm -r $(temp_dir)

config/crd/kustomization.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- mcad
5+
- quota.codeflare_quotasubtrees.yaml
6+
- workload.codeflare_appwrappers.yaml
7+
- workload.codeflare_schedulingspecs.yaml
8+
69
#+kubebuilder:scaffold:crdkustomizeresource

config/crd/mcad/kustomization.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- github.com/project-codeflare/multi-cluster-app-dispatcher/config/crd?ref=v0.0.0 # kpt-set: ${MCAD_CRD}
4+
- github.com/project-codeflare/multi-cluster-app-dispatcher/config/crd?ref=v1.36.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.9.2
6+
creationTimestamp: null
7+
name: quotasubtrees.quota.codeflare.dev
8+
spec:
9+
group: quota.codeflare.dev
10+
names:
11+
kind: QuotaSubtree
12+
listKind: QuotaSubtreeList
13+
plural: quotasubtrees
14+
singular: quotasubtree
15+
scope: Namespaced
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: QuotaSubtree is a specification for a quota subtree resource
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: QuotaSubtreeSpec is the spec for a resource plan
36+
properties:
37+
children:
38+
items:
39+
description: Child is the spec for a QuotaSubtree resource
40+
properties:
41+
name:
42+
type: string
43+
namespace:
44+
type: string
45+
path:
46+
type: string
47+
quotas:
48+
description: Quota is the spec for a QuotaSubtree resource
49+
properties:
50+
disabled:
51+
type: boolean
52+
hardLimit:
53+
type: boolean
54+
requests:
55+
additionalProperties:
56+
anyOf:
57+
- type: integer
58+
- type: string
59+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
60+
x-kubernetes-int-or-string: true
61+
type: object
62+
type: object
63+
type: object
64+
type: array
65+
parent:
66+
type: string
67+
parentNamespace:
68+
type: string
69+
type: object
70+
status:
71+
description: QuotaSubtreeStatus is the status for a QuotaSubtree resource
72+
properties:
73+
children:
74+
items:
75+
description: ResourceAllocation is the spec for the child status
76+
properties:
77+
allocated:
78+
description: ResourceAllocationStatus is the spec for the child
79+
resource usage
80+
properties:
81+
requests:
82+
additionalProperties:
83+
type: string
84+
type: object
85+
type: object
86+
name:
87+
type: string
88+
namespace:
89+
type: string
90+
path:
91+
type: string
92+
type: object
93+
type: array
94+
totalAllocation:
95+
description: ResourceAllocation is the spec for the child status
96+
properties:
97+
allocated:
98+
description: ResourceAllocationStatus is the spec for the child
99+
resource usage
100+
properties:
101+
requests:
102+
additionalProperties:
103+
type: string
104+
type: object
105+
type: object
106+
name:
107+
type: string
108+
namespace:
109+
type: string
110+
path:
111+
type: string
112+
type: object
113+
required:
114+
- children
115+
- totalAllocation
116+
type: object
117+
required:
118+
- spec
119+
type: object
120+
served: true
121+
storage: true
122+
---

0 commit comments

Comments
 (0)