Skip to content

Commit

Permalink
adding configmap creation
Browse files Browse the repository at this point in the history
  • Loading branch information
djkormo committed Jul 5, 2022
1 parent 15301c9 commit 97b5964
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ make run
bash prepare-setup.sh
make docker-build docker-push IMG=$IMG
make docker-build docker-push IMG="docker.io/djkormo/go-project-operator:v0.0.6"
make docker-build docker-push IMG="docker.io/djkormo/go-project-operator:v0.0.8"
```

Expand Down
4 changes: 2 additions & 2 deletions charts/go-project-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ 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.0.7
version: 0.0.8
# 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.0.7"
appVersion: "0.0.8"
2 changes: 1 addition & 1 deletion charts/go-project-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ controllerManager:
manager:
image:
repository: docker.io/djkormo/go-project-operator
tag: v0.0.7
tag: v0.0.8
resources:
limits:
cpu: 500m
Expand Down
4 changes: 3 additions & 1 deletion controllers/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controllers

// for pausing operator loop
const (
// for pausing operator loop
pauseReconciliationLabel = "project-operator/pauseReconciliation"
// for creating configmap
configMapName = "project-operator-configmap-override"
)
40 changes: 40 additions & 0 deletions controllers/project_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,33 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, nil
}

// creating missing override configmap

configMapFound := &corev1.ConfigMap{}
err = r.Get(ctx, types.NamespacedName{Name: configMapName, Namespace: Project.Name}, configMapFound)

// Find if namespace exists
namespaceFound := &corev1.Namespace{}
err = r.Get(ctx, types.NamespacedName{Name: Project.Name}, namespaceFound)

if err != nil && errors.IsNotFound(err) {
// define a new configmap
cm := r.populateConfigOverrideConfigMap(Project) // returns a configmap
logger.Info("Creating a new Configmap", "ConfigMap.Name", configMapName)
err = r.Create(ctx, cm)
if err != nil {
logger.Error(err, "Failed to create new ConfigMap", "Configmap.Name", configMapName)
return ctrl.Result{}, err
}
// configmap created, return and requeue
logger.Info("ConfigMap created", "ConfiMap.Name", configMapName)
return ctrl.Result{Requeue: true}, nil
} else if err != nil {
logger.Error(err, "Failed to get ConfigMap")
// Reconcile failed due to error - requeue
return ctrl.Result{}, err
}

if err != nil && errors.IsNotFound(err) {
// define a new namespace
ns := r.namespaceForProjectApp(Project) // namespaceForProjectApp() returns a namespace
Expand Down Expand Up @@ -362,3 +385,20 @@ func ignoreDeletionPredicate() predicate.Predicate {
},
}
}

func (r *ProjectReconciler) populateConfigOverrideConfigMap(m *projectv1alpha1.Project) *corev1.ConfigMap {

placeholderConfig := map[string]string{
"pauseReconciliationLabel": pauseReconciliationLabel,
}
namespace := m.Namespace
configmap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configMapName,
Namespace: namespace,
},
Data: placeholderConfig,
}

return configmap
}

0 comments on commit 97b5964

Please sign in to comment.