diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index 9e9297b..ec9a1cf 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -64,6 +64,7 @@ jobs: version: v3.10.0 - name: Run chart-releaser + if: github.ref == 'refs/heads/main' uses: helm/chart-releaser-action@v1.4.1 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file diff --git a/Makefile b/Makefile index 4f0bdca..37cd753 100644 --- a/Makefile +++ b/Makefile @@ -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") diff --git a/charts/kwasm-operator/Chart.yaml b/charts/kwasm-operator/Chart.yaml index 9cbfa71..a5b373c 100644 --- a/charts/kwasm-operator/Chart.yaml +++ b/charts/kwasm-operator/Chart.yaml @@ -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" diff --git a/charts/kwasm-operator/templates/deployment.yaml b/charts/kwasm-operator/templates/deployment.yaml index d0f3ed7..f3b9186 100644 --- a/charts/kwasm-operator/templates/deployment.yaml +++ b/charts/kwasm-operator/templates/deployment.yaml @@ -30,6 +30,8 @@ spec: env: - name: CONTROLLER_NAMESPACE value: {{ .Release.Namespace }} + - name: AUTO_PROVISION_NODES + value: {{ .Values.kwasmOperator.autoProvision | quote }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/charts/kwasm-operator/values.yaml b/charts/kwasm-operator/values.yaml index f9d9798..f884999 100644 --- a/charts/kwasm-operator/values.yaml +++ b/charts/kwasm-operator/values.yaml @@ -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 diff --git a/controllers/provisioner_controller.go b/controllers/provisioner_controller.go index 603a09d..b52875d 100644 --- a/controllers/provisioner_controller.go +++ b/controllers/provisioner_controller.go @@ -36,7 +36,8 @@ import ( // ProvisionerReconciler reconciles a Provisioner object type ProvisionerReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + AutoProvision bool Clock } @@ -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) @@ -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.") diff --git a/main.go b/main.go index d3071cf..b22f110 100644 --- a/main.go +++ b/main.go @@ -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. @@ -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)