Skip to content

K8SPS-269 add labels for all objects created by operator #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/ps/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *PerconaServerMySQLReconciler) reconcileCustomConfiguration(ctx context.
return "", errors.New("resources.limits[memory] or resources.requests[memory] should be specified for template usage in configuration")
}

cm := k8s.ConfigMap(cmName, cr.Namespace, configurable.GetConfigMapKey(), configuration)
cm := k8s.ConfigMap(cmName, cr.Namespace, configurable.GetConfigMapKey(), configuration, cr)
if !reflect.DeepEqual(currCm.Data, cm.Data) {
if err := k8s.EnsureObject(ctx, r.Client, cr, cm, r.Scheme); err != nil {
return "", errors.Wrapf(err, "ensure ConfigMap/%s", cmName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/ps/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (r *PerconaServerMySQLReconciler) reconcileMySQLAutoConfig(ctx context.Cont
config += autotuneParams
}

configMap := k8s.ConfigMap(mysql.AutoConfigMapName(cr), cr.Namespace, mysql.CustomConfigKey, config)
configMap := k8s.ConfigMap(mysql.AutoConfigMapName(cr), cr.Namespace, mysql.CustomConfigKey, config, cr)
if !reflect.DeepEqual(currentConfigMap.Data, configMap.Data) {
if err := k8s.EnsureObject(ctx, r.Client, cr, configMap, r.Scheme); err != nil {
return errors.Wrapf(err, "ensure ConfigMap/%s", configMap.Name)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/psbackup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *PerconaServerMySQLBackupReconciler) Reconcile(ctx context.Context, req

if cluster.Spec.Backup == nil || !cluster.Spec.Backup.Enabled {
status.State = apiv1alpha1.BackupError
status.StateDesc = "spec.backup stanza not found in PerconaServerMySQL CustomResource or backup is disabled"
status.StateDesc = "spec.backup not found in PerconaServerMySQL CustomResource or backup is disabled"
return rr, nil
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func (r *PerconaServerMySQLBackupReconciler) createBackupJob(ctx context.Context
switch storage.Type {
case apiv1alpha1.BackupStorageS3:
if storage.S3 == nil {
return errors.New("s3 stanza is required in storage")
return errors.New("s3 is required in storage")
}

nn := types.NamespacedName{Name: storage.S3.CredentialsSecret, Namespace: cr.Namespace}
Expand All @@ -279,7 +279,7 @@ func (r *PerconaServerMySQLBackupReconciler) createBackupJob(ctx context.Context
status.Destination = destination
case apiv1alpha1.BackupStorageGCS:
if storage.GCS == nil {
return errors.New("gcs stanza is required in storage")
return errors.New("gcs is required in storage")
}

nn := types.NamespacedName{Name: storage.GCS.CredentialsSecret, Namespace: cr.Namespace}
Expand All @@ -299,7 +299,7 @@ func (r *PerconaServerMySQLBackupReconciler) createBackupJob(ctx context.Context
status.Destination = destination
case apiv1alpha1.BackupStorageAzure:
if storage.Azure == nil {
return errors.New("azure stanza is required in storage")
return errors.New("azure is required in storage")
}

nn := types.NamespacedName{Name: storage.Azure.CredentialsSecret, Namespace: cr.Namespace}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/psbackup/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestBackupStatusErrStateDesc(t *testing.T) {
}
},
),
stateDesc: "spec.backup stanza not found in PerconaServerMySQL CustomResource or backup is disabled",
stateDesc: "spec.backup not found in PerconaServerMySQL CustomResource or backup is disabled",
},
{
name: "without storage",
Expand Down
6 changes: 5 additions & 1 deletion pkg/k8s/configmap.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package k8s

import (
apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1"
"github.com/percona/percona-server-mysql-operator/pkg/naming"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func ConfigMap(name, namespace, filename, data string) *corev1.ConfigMap {
func ConfigMap(name, namespace, filename, data string, cr *apiv1alpha1.PerconaServerMySQL) *corev1.ConfigMap {

return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -14,6 +17,7 @@ func ConfigMap(name, namespace, filename, data string) *corev1.ConfigMap {
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: naming.Labels(name, cr.Name, "percona-server", "database"),
},
Data: map[string]string{
filename: data,
Expand Down
Loading