Skip to content
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

Remove ensureSecret and use one from lib-common #763

Open
wants to merge 1 commit 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
77 changes: 3 additions & 74 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -43,6 +42,7 @@
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/lib-common/modules/openstack"
)
Expand Down Expand Up @@ -148,84 +148,13 @@
return true
}

type conditionUpdater interface {
Set(c *condition.Condition)
MarkTrue(t condition.Type, messageFormat string, messageArgs ...interface{})
}

// ensureSecret - ensures that the Secret object exists and the expected fields
// are in the Secret. It returns a hash of the values of the expected fields.
func ensureSecret(
ctx context.Context,
secretName types.NamespacedName,
expectedFields []string,
reader client.Reader,
conditionUpdater conditionUpdater,
requeueTimeout time.Duration,
) (string, ctrl.Result, corev1.Secret, error) {
secret := &corev1.Secret{}
err := reader.Get(ctx, secretName, secret)
if err != nil {
if k8s_errors.IsNotFound(err) {
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
fmt.Sprintf(novav1.InputReadyWaitingMessage, "secret/"+secretName.Name)))
return "",
ctrl.Result{RequeueAfter: requeueTimeout},
*secret,
fmt.Errorf("secret %s not found", secretName)
}
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return "", ctrl.Result{}, *secret, err
}

// collect the secret values the caller expects to exist
values := [][]byte{}
for _, field := range expectedFields {
val, ok := secret.Data[field]
if !ok {
err := fmt.Errorf("field '%s' not found in secret/%s", field, secretName.Name)
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return "", ctrl.Result{}, *secret, err
}
values = append(values, val)
}

// TODO(gibi): Do we need to watch the Secret for changes?

hash, err := util.ObjectHash(values)
if err != nil {
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return "", ctrl.Result{}, *secret, err
}

return hash, ctrl.Result{}, *secret, nil
}

// ensureNetworkAttachments - checks the requested network attachments exists and
// returns the annotation to be set on the deployment objects.
func ensureNetworkAttachments(
ctx context.Context,
h *helper.Helper,
networkAttachments []string,
conditionUpdater conditionUpdater,
conditionUpdater common_secret.ConditionUpdater,

Check failure on line 157 in controllers/common.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.ConditionUpdater
requeueTimeout time.Duration,
) (map[string]string, ctrl.Result, error) {
var nadAnnotations map[string]string
Expand Down Expand Up @@ -550,7 +479,7 @@
h *helper.Helper,
namespaceName string,
memcachedName string,
conditionUpdater conditionUpdater,
conditionUpdater common_secret.ConditionUpdater,

Check failure on line 482 in controllers/common.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.ConditionUpdater
) (*memcachedv1.Memcached, error) {
memcached, err := memcachedv1.GetMemcachedByName(ctx, h, memcachedName, namespaceName)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"

Expand Down Expand Up @@ -240,7 +240,7 @@
instance.Spec.PasswordSelectors.MetadataSecret,
}

_, result, secret, err := ensureSecret(
_, result, secret, err := common_secret.EnsureSecret(

Check failure on line 243 in controllers/nova_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
expectedSelectors,
Expand Down Expand Up @@ -798,7 +798,7 @@
}

configHash := make(map[string]env.Setter)
err = secret.EnsureSecrets(ctx, h, instance, cms, &configHash)
err = common_secret.EnsureSecrets(ctx, h, instance, cms, &configHash)

return configHash, scriptName, configName, err
}
Expand Down Expand Up @@ -1662,7 +1662,7 @@
CustomData: data,
}

err := secret.EnsureSecrets(ctx, h, instance, []util.Template{template}, nil)
err := common_secret.EnsureSecrets(ctx, h, instance, []util.Template{template}, nil)

return secretName, err
}
Expand Down Expand Up @@ -1702,7 +1702,7 @@
CustomData: data,
}

err := secret.EnsureSecrets(ctx, h, instance, []util.Template{template}, nil)
err := common_secret.EnsureSecrets(ctx, h, instance, []util.Template{template}, nil)

return secretName, err
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"

keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1"
"github.com/openstack-k8s-operators/nova-operator/pkg/nova"
"github.com/openstack-k8s-operators/nova-operator/pkg/novaapi"
Expand Down Expand Up @@ -175,7 +176,7 @@
// detect if something is changed.
hashes := make(map[string]env.Setter)

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 179 in controllers/novaapi_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
// TODO(gibi): add keystoneAuthURL here is that is also passed via
Expand Down
3 changes: 2 additions & 1 deletion controllers/novacell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"

Expand Down Expand Up @@ -137,7 +138,7 @@
}()

// For the compute config generation we need to read the input secrets
_, result, secret, err := ensureSecret(
_, result, secret, err := common_secret.EnsureSecret(

Check failure on line 141 in controllers/novacell_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
[]string{
Expand Down
3 changes: 2 additions & 1 deletion controllers/novacompute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
Expand Down Expand Up @@ -150,7 +151,7 @@

hashes := make(map[string]env.Setter)

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 154 in controllers/novacompute_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
[]string{
Expand Down
3 changes: 2 additions & 1 deletion controllers/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
Expand Down Expand Up @@ -176,7 +177,7 @@
TransportURLSelector,
}

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 180 in controllers/novaconductor_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
requiredSecretFields,
Expand Down
2 changes: 1 addition & 1 deletion controllers/novametadata_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
TransportURLSelector,
}

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 177 in controllers/novametadata_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
expectedSelectors,
Expand Down
3 changes: 2 additions & 1 deletion controllers/novanovncproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
Expand Down Expand Up @@ -168,7 +169,7 @@

hashes := make(map[string]env.Setter)

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 172 in controllers/novanovncproxy_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
[]string{
Expand Down
3 changes: 2 additions & 1 deletion controllers/novascheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"context"
"fmt"

common_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -169,7 +170,7 @@
// detect if something is changed.
hashes := make(map[string]env.Setter)

secretHash, result, secret, err := ensureSecret(
secretHash, result, secret, err := common_secret.EnsureSecret(

Check failure on line 173 in controllers/novascheduler_controller.go

View workflow job for this annotation

GitHub Actions / Build

undefined: common_secret.EnsureSecret
ctx,
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Secret},
// TODO(gibi): add keystoneAuthURL here is that is also passed via
Expand Down
Loading