Skip to content

Commit

Permalink
helm: reduce CRD duplication by reusing CRDs from root directory
Browse files Browse the repository at this point in the history
Rather than having redundant copies of CRDs within the helm directories,
reuse CRDs from the top-level 'config/crd/bases' directory.

Signed-off-by: Feruzjon Muyassarov <[email protected]>
  • Loading branch information
fmuyassarov committed Jan 25, 2024
1 parent 7e3ede7 commit 749d8ad
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1,623 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
find "$CHARTS_DIR" -name values.yaml | xargs -I '{}' \
sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" -i '{}'
helm package --version "$GITHUB_REF_NAME" --app-version "$GITHUB_REF_NAME" "$CHARTS_DIR"/*
make helm-package
find . -name '*.tgz' -print | while read SRC_FILE; do
DEST_FILE=$(echo $SRC_FILE | sed 's/v/helm-chart-v/g')
mv $SRC_FILE $DEST_FILE
Expand Down
39 changes: 24 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,28 @@ generate-clients: $(GENERATE_GROUPS)
generate-go:
$(Q)$(GO_CMD) generate ./...

# rule to update generated CRDs in our helm charts
.PHONY: update-helm-crds
update-helm-crds:
$(Q)for plugin in $(PLUGINS); do \
plugin="$${plugin#nri-}"; plugin="$${plugin#resource-policy-}"; \
helm_dir=$(HELM_TOP_DIR)/$$plugin/crds; \
if [ ! -d "$$helm_dir" ]; then \
echo "No generated CRD found for $$plugin plugin..."; \
else \
echo "Updating Helm chart CRDs for $$plugin plugin..."; \
cp $(CRD_BASE_DIR)/*_$${plugin//-/}*.yaml $$helm_dir; \
fi; \
done

# top level rule to (re)generate everything we need
generate: generate-go generate-types generate-manifests generate-clients update-helm-crds
generate: generate-go generate-types generate-manifests generate-clients

CRD_BASE_DIR := config/crd/bases
HELM_TOP_DIR := deployment/helm

.PHONY: helm-package
helm-package: copy-helm-crds
helm package --version $(IMAGE_VERSION) --app-version $(IMAGE_VERSION) $(HELM_TOP_DIR)/*
$(MAKE) cleanup-helm-crds

.PHONY: copy-helm-crds
copy-helm-crds: ## Copy CRDs root directory to helm directory for packaging.
cp $(CRD_BASE_DIR)/topology.node.k8s.io_noderesourcetopologies.yaml $(HELM_TOP_DIR)/balloons/crds
cp $(CRD_BASE_DIR)/config.nri_balloonspolicies.yaml $(HELM_TOP_DIR)/balloons/crds
cp $(CRD_BASE_DIR)/topology.node.k8s.io_noderesourcetopologies.yaml $(HELM_TOP_DIR)/template/crds
cp $(CRD_BASE_DIR)/config.nri_templatepolicies.yaml $(HELM_TOP_DIR)/template/crds
cp $(CRD_BASE_DIR)/topology.node.k8s.io_noderesourcetopologies.yaml $(HELM_TOP_DIR)/topology-aware/crds
cp $(CRD_BASE_DIR)/config.nri_topologyawarepolicies.yaml $(HELM_TOP_DIR)/topology-aware/crds

.PHONY: cleanup-helm-crds
cleanup-helm-crds: ## Clean up temporarily copied CRDs.
rm -f $(HELM_TOP_DIR)/balloons/crds/*
rm -f $(HELM_TOP_DIR)/template/crds/*
rm -f $(HELM_TOP_DIR)/topology-aware/crds/*
349 changes: 0 additions & 349 deletions deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml

This file was deleted.

270 changes: 0 additions & 270 deletions deployment/helm/balloons/crds/noderesourcetopology.yaml

This file was deleted.

Loading

0 comments on commit 749d8ad

Please sign in to comment.