Skip to content
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

Merge cosmo-* helm charts into a single chart #778

Merged
merged 13 commits into from
Jul 18, 2023
85 changes: 4 additions & 81 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ DASHBOARD_VERSION ?= $(VERSION)
COSMOCTL_VERSION ?= $(VERSION)
TRAEFIK_PLUGINS_VERSION ?= $(VERSION)


CHART_MANAGER_VERSION ?= $(MANAGER_VERSION)
CHART_DASHBOARD_VERSION ?= $(DASHBOARD_VERSION)
CHART_TRAEFIK_VERSION ?= $(TRAEFIK_PLUGINS_VERSION)
CHART_VERSION ?= $(VERSION)

IMG_MANAGER ?= cosmo-controller-manager:$(MANAGER_VERSION)
IMG_DASHBOARD ?= cosmo-dashboard:$(DASHBOARD_VERSION)
Expand Down Expand Up @@ -51,68 +48,11 @@ all: manager cosmoctl dashboard
##---------------------------------------------------------------------
##@ Development
##---------------------------------------------------------------------
define WEBHOOK_CHART_SUFIX
---
{{- if not $$.Values.enableCertManager }}
apiVersion: v1
kind: Secret
metadata:
name: webhook-server-cert
namespace: {{ .Release.Namespace }}
labels:
{{- include "cosmo-controller-manager.labels" . | nindent 4 }}
type: kubernetes.io/tls
data:
ca.crt: {{ $$tls.caCert }}
tls.crt: {{ $$tls.clientCert }}
tls.key: {{ $$tls.clientKey }}
{{- else }}
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
labels:
{{- include "cosmo-controller-manager.labels" . | nindent 4 }}
name: cosmo-serving-cert
namespace: {{ .Release.Namespace }}
spec:
dnsNames:
- cosmo-webhook-service.{{ .Release.Namespace }}.svc
- cosmo-webhook-service.{{ .Release.Namespace }}.svc.cluster.local
issuerRef:
kind: ClusterIssuer
name: cosmo-selfsigned-clusterissuer
secretName: webhook-server-cert
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
labels:
{{- include "cosmo-controller-manager.labels" . | nindent 4 }}
name: cosmo-selfsigned-clusterissuer
namespace: {{ .Release.Namespace }}
spec:
selfSigned: {}
{{- end }}
endef

WEBHOOK_CHART_YAML ?= charts/cosmo-controller-manager/templates/webhook.yaml

export WEBHOOK_CHART_SUFIX
gen-charts: kustomize
cp config/crd/bases/* charts/cosmo-controller-manager/crds/
# cp config/user-addon/traefik-middleware/useraddon-*.yaml charts/cosmo-dashboard/templates/
$(KUSTOMIZE) build config/webhook-chart \
| sed -e 's/namespace: system/namespace: {{ .Release.Namespace }}/g' \
| sed -z 's;apiVersion: v1\nkind: Service\nmetadata:\n name: cosmo-webhook-service\n namespace: {{ .Release.Namespace }}\nspec:\n ports:\n - port: 443\n targetPort: 9443\n selector:\n control-plane: controller-manager;{{ $$tls := fromYaml ( include "cosmo-controller-manager.gen-certs" . ) }};g' \
| sed -z 's;creationTimestamp: null;{{- if $$.Values.enableCertManager }}\n annotations:\n cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-serving-cert\n {{- end }}\n labels:\n {{- include "cosmo-controller-manager.labels" . | nindent 4 }};g' \
| sed -z 's;clientConfig:;clientConfig:\n caBundle: {{ if not $$.Values.enableCertManager -}}{{ $$tls.caCert }}{{- else -}}Cg=={{ end }};g' > $(WEBHOOK_CHART_YAML)
echo "$$WEBHOOK_CHART_SUFIX" >> $(WEBHOOK_CHART_YAML)

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
ifeq ($(QUICK_BUILD),no)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
make gen-charts
endif

.PHONY: generate
Expand All @@ -125,11 +65,6 @@ endif
proto-generate: ## Generate code protocol buffer api.
make -C proto/ all

.PHONY: chart-check
chart-check: helm gen-charts
./hack/diff-chart-kust.sh controller-manager
./hack/diff-chart-kust.sh dashboard

.PHONY: fmt
fmt: go ## Run go fmt against code.
ifeq ($(QUICK_BUILD),no)
Expand Down Expand Up @@ -223,22 +158,10 @@ endif
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG_MANAGER}
cd config/dashboard && $(KUSTOMIZE) edit set image dashboard=${IMG_DASHBOARD}
sed -i.bk \
-e "s/version: [0-9]\+.[0-9]\+.[0-9]\+.*/version: ${CHART_MANAGER_VERSION:v%=%}/" \
-e "s/appVersion: v[0-9]\+.[0-9]\+.[0-9]\+.*/appVersion: ${MANAGER_VERSION}/" \
-e 's;artifacthub.io/prerelease: "\(true\|false\)";artifacthub.io/prerelease: "$(PRERELEASE)";' \
charts/cosmo-controller-manager/Chart.yaml
sed -i.bk \
-e "s/version: [0-9]\+.[0-9]\+.[0-9]\+.*/version: ${CHART_DASHBOARD_VERSION:v%=%}/" \
-e "s/appVersion: v[0-9]\+.[0-9]\+.[0-9]\+.*/appVersion: ${DASHBOARD_VERSION}/" \
-e "s/version: [0-9]\+.[0-9]\+.[0-9]\+.*/version: ${CHART_VERSION:v%=%}/" \
-e "s/appVersion: v[0-9]\+.[0-9]\+.[0-9]\+.*/appVersion: ${VERSION}/" \
-e 's;artifacthub.io/prerelease: "\(true\|false\)";artifacthub.io/prerelease: "$(PRERELEASE)";' \
charts/cosmo-dashboard/Chart.yaml
sed -i.bk \
-e "s/version: [0-9]\+.[0-9]\+.[0-9]\+.*/version: ${CHART_TRAEFIK_VERSION:v%=%}/" \
-e 's;artifacthub.io/prerelease: "\(true\|false\)";artifacthub.io/prerelease: "$(PRERELEASE)";' \
charts/cosmo-traefik/Chart.yaml
sed -i.bk \
-e "s;image: ghcr.io/cosmo-workspace/cosmo-traefik-plugins:v[0-9]\+.[0-9]\+.[0-9]\+.*;image: ghcr.io/cosmo-workspace/cosmo-traefik-plugins:${CHART_TRAEFIK_VERSION};" \
charts/cosmo-traefik/values.yaml
charts/cosmo/Chart.yaml

##---------------------------------------------------------------------
##@ Run
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/cluster_template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type TemplateObject interface {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope="Cluster",shortName=ctmpl
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.metadata.labels.cosmo-workspace\.github\.io/type`
// ClusterTemplate is the Schema for the Templates API
type ClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func init() {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope="Cluster",shortName=tmpl
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.metadata.labels.cosmo-workspace\.github\.io/type`
// Template is the Schema for the Templates API
type Template struct {
metav1.TypeMeta `json:",inline"`
Expand Down
45 changes: 45 additions & 0 deletions charts/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

HELM = ../bin/helm
KUSTOMIZE = ../bin/kustomize

helm:
make -C ../ helm

helm-dependency-update:
cd cosmo; ../$(HELM) dependency update

chartsnap:
go install github.com/cosmo-workspace/controller-testtools/cmd/chartsnap@latest

TEST_VALUES ?= cosmo/test

test: chartsnap helm helm-dependency-update
chartsnap --chart cosmo --values $(TEST_VALUES) --helm-path $(HELM) $(CHARTSNAP_OPT)

test-list:
grep -R '{{[-|] if .*}}' cosmo/templates/* | grep .Values | awk -F':' '{print $$2}' | sed -n 's/.*\(.Values[^ ]*\).*/\1/p' | tr -d ')' | sort | uniq | awk -F'.Values.' '{print $$2}' > cosmo/test/if-values.list

update-charts: crd cosmo-username-headers-addon.yaml webhook.yaml

crd:
cp ../config/crd/bases/* cosmo/crds/

ADDON_YAML ?= cosmo/templates/cosmo-username-headers-addon.yaml

cosmo-username-headers-addon.yaml:
echo '{{- if .Values.installDefaultUserAddon }}' > $(ADDON_YAML)
cat ../config/user-addon/traefik-middleware/cosmo-username-headers-addon.yaml \
| sed -e 's/{{INSTANCE}}/{{ print "{{INSTANCE}}" }}/g' \
| sed -e 's/{{TEMPLATE}}/{{ print "{{TEMPLATE}}" }}/g' \
| sed -e 's/{{NAMESPACE}}/{{ print "{{NAMESPACE}}" }}/g' \
| sed -e 's/{{USER_NAME}}/{{ print "{{USER_NAME}}" }}/g' >> $(ADDON_YAML)
echo '{{- end }}' >> $(ADDON_YAML)

WEBHOOK_CHART_YAML ?= cosmo/templates/controller-manager/webhook.yaml
webhook.yaml:
$(KUSTOMIZE) build ../config/webhook-chart \
| sed -e 's/namespace: system/namespace: {{ .Release.Namespace }}/g' \
| sed -z 's;apiVersion: v1\nkind: Service\nmetadata:\n name: cosmo-webhook-service\n namespace: {{ .Release.Namespace }}\nspec:\n ports:\n - port: 443\n targetPort: 9443\n selector:\n control-plane: controller-manager\n---;{{ $$tls := fromYaml ( include "cosmo.webhook.gen-certs" . ) }}\n---\n{{- if $$.Values.controllerManager.webhook.enabled }};g' \
| sed -z 's;creationTimestamp: null;{{- if $$.Values.certManager.enabled }}\n annotations:\n cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-webhook-cert\n {{- end }}\n labels:\n {{- include "cosmo.labels" . | nindent 4 }};g' \
| sed -z 's;clientConfig:;clientConfig:\n caBundle: {{ if not $$.Values.certManager.enabled -}}{{ $$tls.caCert }}{{- else -}}Cg=={{ end }};g' > $(WEBHOOK_CHART_YAML)
echo '{{- end }}' >> $(WEBHOOK_CHART_YAML)
25 changes: 0 additions & 25 deletions charts/cosmo-controller-manager/Chart.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions charts/cosmo-controller-manager/README.md

This file was deleted.

1 change: 0 additions & 1 deletion charts/cosmo-controller-manager/templates/NOTES.txt

This file was deleted.

74 changes: 0 additions & 74 deletions charts/cosmo-controller-manager/templates/_helpers.tpl

This file was deleted.

Loading
Loading