Skip to content

Commit

Permalink
Add environment variable to enable auto provisioning AUTO_PROVISION_N…
Browse files Browse the repository at this point in the history
…ODES

Signed-off-by: Sven Pfennig <[email protected]>
  • Loading branch information
0xE282B0 committed Nov 14, 2022
1 parent ad48a03 commit caea6ac
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
version: v3.10.0
-
name: Run chart-releaser
if: github.ref == 'refs/heads/main'
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= v0.1.0
VERSION ?= v0.2.0

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down
4 changes: 2 additions & 2 deletions charts/kwasm-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.0"
appVersion: "0.2.0"
2 changes: 2 additions & 0 deletions charts/kwasm-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ spec:
env:
- name: CONTROLLER_NAMESPACE
value: {{ .Release.Namespace }}
- name: AUTO_PROVISION_NODES
value: {{ .Values.kwasmOperator.autoProvision }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
5 changes: 4 additions & 1 deletion charts/kwasm-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ image:
repository: ghcr.io/kwasm/kwasm-operator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: kwasm-operator-0.1.0
tag: kwasm-operator-0.2.0

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

kwasmOperator:
autoProvision: "false"

serviceAccount:
# Specifies whether a service account should be created
create: true
Expand Down
9 changes: 5 additions & 4 deletions controllers/provisioner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import (
// ProvisionerReconciler reconciles a Provisioner object
type ProvisionerReconciler struct {
client.Client
Scheme *runtime.Scheme
Scheme *runtime.Scheme
AutoProvision bool
Clock
}

Expand Down Expand Up @@ -93,13 +94,13 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
labelShouldBePresent := node.Annotations[addKWasmNodeLabelAnnotation] == "true"
labelIsPresent := node.Labels[nodeNameLabel] == node.Name

if labelShouldBePresent == labelIsPresent {
if labelShouldBePresent == labelIsPresent && !r.AutoProvision {
// The desired state and actual state of the Node are the same.
// No further action is required by the operator at this moment.

return ctrl.Result{}, nil
}
if labelShouldBePresent {
if labelShouldBePresent || r.AutoProvision && !labelIsPresent {
// If the label should be set but is not, set it.
if node.Labels == nil {
node.Labels = make(map[string]string)
Expand All @@ -113,7 +114,7 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}

} else {
} else if !r.AutoProvision {
// If the label should not be set but is, remove it.
delete(node.Labels, nodeNameLabel)
log.Info().Msg("Label removed. Removing Job.")
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"os"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -105,9 +106,16 @@ func main() {
os.Exit(1)
}

var autoProvision = false
if autoProvisionEnv, found := os.LookupEnv("AUTO_PROVISION_NODES"); found && strings.ToLower(autoProvisionEnv) == "true" {
autoProvision = true
setupLog.Info("AUTO_PROVISION_NODES enabled")
}

if err = (&controllers.ProvisionerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
AutoProvision: autoProvision,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Provisioner")
os.Exit(1)
Expand Down

0 comments on commit caea6ac

Please sign in to comment.