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

Managedidentity operatorspec secrets #3937

Merged
merged 5 commits into from
Apr 18, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*/

package customizations

import (
"context"
"fmt"

v20230131s "github.com/Azure/azure-service-operator/v2/api/managedidentity/v1api20230131/storage"
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
. "github.com/Azure/azure-service-operator/v2/internal/logging"
"github.com/Azure/azure-service-operator/v2/internal/util/to"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/secrets"
"github.com/go-logr/logr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

var _ genruntime.KubernetesExporter = &UserAssignedIdentityExtension{}

// ExportKubernetesResources defines a resource which can create other resources in Kubernetes.
func (identity *UserAssignedIdentityExtension) ExportKubernetesResources(
ctx context.Context,
obj genruntime.MetaObject,
armClient *genericarmclient.GenericClient,
log logr.Logger,
) ([]client.Object, error) {
typedObj, ok := obj.(*v20230131s.UserAssignedIdentity)
if !ok {
return nil, fmt.Errorf(
"cannot run on unknown resource type %T, expected *v20230131s.UserAssignedIdentity", obj)
}

// Type assert that we are the hub type. This will fail to compile if
// the hub type has been changed but this extension has not
var _ conversion.Hub = typedObj

hasSecrets := secretsSpecified(typedObj)
if !hasSecrets {
log.V(Debug).Info("No secrets retrieval to perform as operatorSpec.Secrets is empty")
return nil, nil
}

collector := secrets.NewCollector(typedObj.Namespace)
if typedObj.Spec.OperatorSpec != nil && typedObj.Spec.OperatorSpec.Secrets != nil {
matthchr marked this conversation as resolved.
Show resolved Hide resolved
collector.AddValue(typedObj.Spec.OperatorSpec.Secrets.ClientId, to.Value(typedObj.Status.ClientId))
collector.AddValue(typedObj.Spec.OperatorSpec.Secrets.PrincipalId, to.Value(typedObj.Status.PrincipalId))
collector.AddValue(typedObj.Spec.OperatorSpec.Secrets.TenantId, to.Value(typedObj.Status.TenantId))
}

result, err := collector.Values()
if err != nil {
return nil, err
}
return secrets.SliceToClientObjectSlice(result), nil
}

func secretsSpecified(obj *v20230131s.UserAssignedIdentity) bool {
if obj.Spec.OperatorSpec == nil || obj.Spec.OperatorSpec.Secrets == nil {
return false
}

specSecrets := obj.Spec.OperatorSpec.Secrets
hasSecrets := false
if specSecrets.ClientId != nil ||
specSecrets.PrincipalId != nil ||
specSecrets.TenantId != nil {
hasSecrets = true
}

return hasSecrets
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions v2/api/managedidentity/v1api20230131/storage/structure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ github.com/Azure/azure-service-operator/v2/api/managedidentity/v1api20230131/sto
├── Spec: Object (7 properties)
│ ├── AzureName: string
│ ├── Location: *string
│ ├── OperatorSpec: *Object (2 properties)
│ ├── OperatorSpec: *Object (3 properties)
│ │ ├── ConfigMaps: *Object (4 properties)
│ │ │ ├── ClientId: *genruntime.ConfigMapDestination
│ │ │ ├── PrincipalId: *genruntime.ConfigMapDestination
│ │ │ ├── PropertyBag: genruntime.PropertyBag
│ │ │ └── TenantId: *genruntime.ConfigMapDestination
│ │ └── PropertyBag: genruntime.PropertyBag
│ │ ├── PropertyBag: genruntime.PropertyBag
│ │ └── Secrets: *Object (4 properties)
│ │ ├── ClientId: *genruntime.SecretDestination
│ │ ├── PrincipalId: *genruntime.SecretDestination
│ │ ├── PropertyBag: genruntime.PropertyBag
│ │ └── TenantId: *genruntime.SecretDestination
│ ├── OriginalVersion: string
│ ├── Owner: *genruntime.KnownResourceReference
│ ├── PropertyBag: genruntime.PropertyBag
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions v2/api/managedidentity/v1api20230131/structure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ github.com/Azure/azure-service-operator/v2/api/managedidentity/v1api20230131
│ ├── Spec: Object (5 properties)
│ │ ├── AzureName: string
│ │ ├── Location: *string
│ │ ├── OperatorSpec: *Object (1 property)
│ │ │ └── ConfigMaps: *Object (3 properties)
│ │ │ ├── ClientId: *genruntime.ConfigMapDestination
│ │ │ ├── PrincipalId: *genruntime.ConfigMapDestination
│ │ │ └── TenantId: *genruntime.ConfigMapDestination
│ │ ├── OperatorSpec: *Object (2 properties)
│ │ │ ├── ConfigMaps: *Object (3 properties)
│ │ │ │ ├── ClientId: *genruntime.ConfigMapDestination
│ │ │ │ ├── PrincipalId: *genruntime.ConfigMapDestination
│ │ │ │ └── TenantId: *genruntime.ConfigMapDestination
│ │ │ └── Secrets: *Object (3 properties)
│ │ │ ├── ClientId: *genruntime.SecretDestination
│ │ │ ├── PrincipalId: *genruntime.SecretDestination
│ │ │ └── TenantId: *genruntime.SecretDestination
│ │ ├── Owner: *genruntime.KnownResourceReference
│ │ └── Tags: map[string]string
│ └── Status: Object (10 properties)
Expand Down
Loading
Loading