Skip to content

Commit

Permalink
feat: update charts, fix small conversion bug, add Makefile tasks fo…
Browse files Browse the repository at this point in the history
…r docker loading (#106)

* feat(charts): break into crds and main chart

* feat: update charts, fix small conversion bug, add Makefile tasks for docker loading
  • Loading branch information
austince authored Apr 1, 2020
1 parent c5087c4 commit 83e40cc
Show file tree
Hide file tree
Showing 33 changed files with 6,658 additions and 3,127 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resources.yaml
.charts
*.tgz

vvp-values.yaml
*-values.yaml

## TLS
*.pem
Expand Down
56 changes: 53 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ BUILD=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS?="crd"

DOCKER_REPO=fintechstudios/ververica-platform-k8s-operator

LD_FLAGS="-X $(VERSION_PKG).operatorVersion='$(VERSION)' -X $(VERSION_PKG).gitCommit='$(GIT_COMMIT)' -X $(VERSION_PKG).buildDate='$(BUILD)'"

TEST_CLUSTER_NAME=ververica-platform-k8s-operator-cluster
Expand Down Expand Up @@ -151,22 +153,41 @@ patch-image:
# Build the k8s resources for deployment
.PHONY: kustomize-build
kustomize-build: patch-image
$(KUSTOMIZE) build config/default > resources.yaml
rm -f resources.yaml && $(KUSTOMIZE) build config/default > resources.yaml

# Update the Swagger Client API
.PHONY: swagger-gen
swagger-gen:
./hack/update-app-manager-swagger-codegen.sh \
&& ./hack/update-platform-swagger-codegen.sh

.PHONY: docker-build
docker-build:
docker build -f Dockerfile_build \
--cache-from $(DOCKER_REPO)-builder:$(VERSION) \
--tag $(DOCKER_REPO)-builder:$(VERSION) \
. \
&& docker build \
--build-arg BUILD_IMG=$(DOCKER_REPO)-builder:$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg VERSION=$(VERSION) \
--cache-from $(DOCKER_REPO):$(VERSION) \
-f Dockerfile \
--tag $(DOCKER_REPO):$(VERSION) \
.

.PHONY: test-cluster-load-image
test-cluster-load-image: kind
$(KIND) load docker-image --name $(TEST_CLUSTER_NAME) $(DOCKER_REPO):$(VERSION)

# Create the test cluster using kind
# install local path storage as defult storage class (see: https://github.com/kubernetes-sigs/kind/issues/118#issuecomment-475134086)
.PHONY: test-cluster-create
.PHONY: test-cluster-create kind
test-cluster-create:
$(KIND) create cluster --name $(TEST_CLUSTER_NAME)

# Delete the test cluster using kind
.PHONY: test-cluster-delete
.PHONY: test-cluster-delete kind
test-cluster-delete:
$(KIND) delete cluster --name $(TEST_CLUSTER_NAME)

Expand All @@ -181,3 +202,32 @@ test-cluster-install-vvp:
vvp \
ververica/ververica-platform

.PHONY: test-cluster-install-cert-manager
test-cluster-install-cert-manager:
kubectl apply \
--validate=false \
-f https://github.com/jetstack/cert-manager/releases/download/v0.14.1/cert-manager.crds.yaml \
&& . ./hack/helm-init.sh \
&& helm upgrade --install \
--version v0.14.1 \
--namespace cert-manager \
cert-manager \
jetstack/cert-manager

.PHONY: test-cluster-install-chart
test-cluster-install-chart:
. ./hack/helm-init.sh \
&& helm upgrade --install \
--namespace vvp \
vp-k8s-operator \
./charts/vp-k8s-operator \
-f vp-k8s-values.yaml

.PHONY: test-cluster-install-crds
test-cluster-install-crds:
. ./hack/helm-init.sh \
&& helm upgrade --install \
--namespace default \
vp-k8s-operator-crds \
./charts/vp-k8s-operator-crds \
-f vp-k8s-crds-values.yaml
15 changes: 12 additions & 3 deletions api/v1beta2/vpdeployment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ func convertToDeploymentState(state VpDeploymentState, annotation annotations.An
}

func convertToDeploymentStatus(status *VpDeploymentStatus, notations map[string]string) (v1beta1.VpDeploymentStatus, error) {
v1Status := v1beta1.VpDeploymentStatus{
State: convertToDeploymentState(status.State, annDepStatusState, notations),
v1Status := v1beta1.VpDeploymentStatus{}

if status == nil {
return v1Status, nil
}

v1Status.State = convertToDeploymentState(status.State, annDepStatusState, notations)

if status.Running != nil {
// save the running status as JSON
runningJSON, err := json.Marshal(status.Running)
Expand All @@ -57,7 +61,9 @@ func convertToDeploymentStatus(status *VpDeploymentStatus, notations map[string]

func convertFromDeploymentState(state v1beta1.DeploymentState, annotation annotations.AnnotationName, notations map[string]string) VpDeploymentState {
if annotations.Has(notations, annotation) {
return VpDeploymentState(annotations.Get(notations, annotation))
val := annotations.Get(notations, annotation)
annotations.Remove(notations, annotation)
return VpDeploymentState(val)
}

return VpDeploymentState(string(state))
Expand All @@ -73,6 +79,7 @@ func convertFromDeploymentStatus(v1Status v1beta1.VpDeploymentStatus, notations
if err := json.Unmarshal([]byte(data), &status.Running); err != nil {
return status, err
}
annotations.Remove(notations, annDepStatusRunning)
}

return status, nil
Expand Down Expand Up @@ -114,6 +121,7 @@ func (src *VpDeployment) ConvertTo(dstRaw conversion.Hub) error {
if err := json.Unmarshal([]byte(an), dst.Spec.Spec.StartFromSavepoint); err != nil {
return err
}
annotations.Remove(src.Annotations, annDepStartFromSavepoint)
}

// Spec.Spec template
Expand Down Expand Up @@ -318,6 +326,7 @@ func (dst *VpDeployment) ConvertFrom(srcRaw conversion.Hub) error { // nolint:go
if err := json.Unmarshal([]byte(data), &dstPods.Labels); err != nil {
return err
}
annotations.Remove(src.Annotations, annPodLabels)
}

if srcPods.VolumeMounts != nil {
Expand Down
22 changes: 22 additions & 0 deletions charts/vp-k8s-operator-crds/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions charts/vp-k8s-operator-crds/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for the CRDs that accompany the vp-k8s-operator
name: vp-k8s-operator-crds
version: 0.1.0
Empty file.
Empty file.
72 changes: 72 additions & 0 deletions charts/vp-k8s-operator-crds/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "vp-k8s-operator-crds.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "vp-k8s-operator-crds.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "vp-k8s-operator-crds.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "vp-k8s-operator-crds.labels" -}}
app.kubernetes.io/name: {{ include "vp-k8s-operator-crds.name" . }}
helm.sh/chart: {{ include "vp-k8s-operator-crds.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "vp-k8s-operator-crds.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "vp-k8s-operator-crds.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}


{{/*
Webhook cert injection
*/}}
{{- define "vp-k8s-operator-crds.webhookCert" -}}
{{ printf "%s/%s" (default .Release.Namespace .Values.webhookCert.namespace) .Values.webhookCert.name }}
{{- end -}}


{{/*
Webhook caBundle defaults to newline (PEM-encoded) as a placeholder
*/}}
{{- define "vp-k8s-operator-crds.webhookCaBundle" -}}
{{ default "Cg==" .Values.webhookCert.caBundle }}
{{- end -}}
Loading

0 comments on commit 83e40cc

Please sign in to comment.