-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves configMap functions into their own module
- Loading branch information
Showing
2 changed files
with
45 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmlib | ||
|
||
import ( | ||
"context" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
func LabelCM(ctx context.Context, r client.Client, configMap corev1.ConfigMap, labelKey string, labelValue string) error { | ||
log := log.FromContext(ctx) | ||
labels := configMap.GetLabels() | ||
if labels == nil { | ||
labels = map[string]string{} | ||
} | ||
|
||
labels[labelKey] = labelValue | ||
configMap.SetLabels(labels) | ||
|
||
if err := r.Update(ctx, &configMap); err != nil { | ||
log.Error(err, "Unable to update configMap - setting labels") | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func AnnotateCM(ctx context.Context, r client.Client, configMap corev1.ConfigMap, annotationKey string, annotationValue string) error { | ||
log := log.FromContext(ctx) | ||
annotations := configMap.GetAnnotations() | ||
if annotations == nil { | ||
annotations = map[string]string{} | ||
} | ||
|
||
annotations[annotationKey] = annotationValue | ||
configMap.SetAnnotations(annotations) | ||
|
||
if err := r.Update(ctx, &configMap); err != nil { | ||
log.Error(err, "Unable to update configMap - setting annotations") | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters