-
Notifications
You must be signed in to change notification settings - Fork 237
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
feat: SecretManagerSecret full test coverage & manual replication field #3371
Changes from all commits
94a7548
afde6b9
32a002c
f2edfe4
52f0b95
8825382
792894d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ if [[ -z "${KUBEBUILDER_ASSETS:-}" ]]; then | |
fi | ||
|
||
if [[ -z "${KCC_USE_DIRECT_RECONCILERS:-}" ]]; then | ||
KCC_USE_DIRECT_RECONCILERS=ComputeForwardingRule,GKEHubFeatureMembership,SecretManagerSecret,SecretManagerSecretVersion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test now covers both legacy controller and direct controller (via alpha direct annotation). we no longer need this |
||
KCC_USE_DIRECT_RECONCILERS=ComputeForwardingRule,GKEHubFeatureMembership | ||
fi | ||
echo "Using direct controllers: $KCC_USE_DIRECT_RECONCILERS" | ||
export KCC_USE_DIRECT_RECONCILERS | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,13 @@ func (s *SecretsV1) populateDefaultsForSecret(ctx context.Context, obj *pb.Secre | |
return fmt.Errorf("Aliases cannot be assigned to versions that don't exist") | ||
} | ||
} | ||
// TTL and ExpireTime are OneOf, but the GCP service always converts TTL to expireTime before storing the object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a reasonable behaviour. Maybe we should deprecate spec.ttl (and replace with |
||
if obj.GetTtl() != nil { | ||
expirateTime := timestamppb.Now().AsTime().Add(obj.GetTtl().AsDuration()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: might as well name it the same as the field you're setting, i.e. |
||
obj.Expiration = &pb.Secret_ExpireTime{ | ||
ExpireTime: timestamppb.New(expirateTime), | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -154,6 +161,10 @@ func (s *SecretsV1) UpdateSecret(ctx context.Context, req *pb.UpdateSecretReques | |
updated.Expiration = &pb.Secret_ExpireTime{ | ||
ExpireTime: req.Secret.GetExpireTime(), | ||
} | ||
case "ttl": | ||
updated.Expiration = &pb.Secret_Ttl{ | ||
Ttl: req.Secret.GetTtl(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: really? I would have assumed it would set Expiration.ExpireTime, just like in create. Still if this is what the logs tell us.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I don't know if we have test coverage of this in this PR (?). It's not a big deal, because it's a mock (we can fix it when we need it), just that I would have guessed the other way! In general I think the behaviour of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes... here's what the SecertManager server tells us https://screenshot.googleplex.com/9giJXnHPt3nMSwm.png For the log, the respond is always expire time, no ttl whatever the request says. I uploaded the real log in the git-commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. We set ttl, and then in |
||
} | ||
case "expiration": | ||
updated.Expiration = req.Secret.GetExpiration() | ||
case "rotation.nextRotationTime": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,18 @@ func normalizeExternal(ctx context.Context, reader client.Reader, src client.Obj | |
secret.Spec.Replication.LegacyAutomatic.CustomerManagedEncryption.KmsKeyRef = kmsKeyRef | ||
} | ||
} | ||
if secret.Spec.Replication.UserManaged != nil { | ||
for _, r := range secret.Spec.Replication.UserManaged.Replicas { | ||
if r.CustomerManagedEncryption != nil { | ||
kmsKeyRef := r.CustomerManagedEncryption.KmsKeyRef | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I previously missed this field because I thought it is another field There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a fuzz test :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR on the way. |
||
kmsKeyRef, err := refs.ResolveKMSCryptoKeyRef(ctx, reader, src, kmsKeyRef) | ||
if err != nil { | ||
return err | ||
} | ||
r.CustomerManagedEncryption.KmsKeyRef = kmsKeyRef | ||
} | ||
} | ||
} | ||
} | ||
if len(secret.Spec.TopicRefs) != 0 { | ||
for _, topicRef := range secret.Spec.TopicRefs { | ||
|
@@ -246,7 +258,10 @@ func (a *Adapter) Update(ctx context.Context, op *directbase.UpdateOperation) er | |
if err != nil { | ||
return err | ||
} | ||
|
||
if paths.Has("ttl") { | ||
paths = paths.Delete("ttl") | ||
resource.Expiration = a.actual.Expiration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: there should be a comment here, because I don't think this does anything unless |
||
} | ||
if len(paths) == 0 { | ||
log.V(2).Info("no field needs update", "name", a.id) | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1 | ||
kind: SecretManagerSecret | ||
metadata: | ||
annotations: | ||
cnrm.cloud.google.com/project-id: ${projectId} | ||
labels: | ||
cnrm-test: "true" | ||
label-one: value-one | ||
label-two: value-two | ||
managed-by-cnrm: "true" | ||
name: secretmanagersecret-${uniqueId} | ||
spec: | ||
annotations: | ||
bar: secretmanagersecret-bar | ||
foo: secretmanagersecret | ||
expireTime: "2025-10-03T15:01:23Z" | ||
resourceID: secretmanagersecret-${uniqueId} | ||
rotation: | ||
nextRotationTime: "2025-10-03T15:01:23Z" | ||
rotationPeriod: 3600s | ||
topics: | ||
- topicRef: | ||
external: projects/${projectId}/topics/topic-2-${uniqueId} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1 | ||
kind: SecretManagerSecret | ||
metadata: | ||
annotations: | ||
cnrm.cloud.google.com/management-conflict-prevention-policy: none | ||
cnrm.cloud.google.com/project-id: ${projectId} | ||
cnrm.cloud.google.com/state-into-spec: absent | ||
finalizers: | ||
- cnrm.cloud.google.com/finalizer | ||
- cnrm.cloud.google.com/deletion-defender | ||
generation: 3 | ||
labels: | ||
cnrm-test: "true" | ||
label-one: value-one | ||
label-two: value-two | ||
name: secretmanagersecret-${uniqueId} | ||
namespace: ${uniqueId} | ||
spec: | ||
annotations: | ||
bar: secretmanagersecret-bar | ||
foo: secretmanagersecret | ||
expireTime: "2025-10-03T15:01:23Z" | ||
replication: | ||
automatic: true | ||
resourceID: secretmanagersecret-${uniqueId} | ||
rotation: | ||
nextRotationTime: "2025-10-03T15:01:23Z" | ||
rotationPeriod: 3600s | ||
topics: | ||
- topicRef: | ||
name: topic-2-${uniqueId} | ||
status: | ||
conditions: | ||
- lastTransitionTime: "1970-01-01T00:00:00Z" | ||
message: The resource is up to date | ||
reason: UpToDate | ||
status: "True" | ||
type: Ready | ||
name: projects/${projectNumber}/secrets/secretmanagersecret-${uniqueId} | ||
observedGeneration: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TTL is a stale field that causes customers issues: it uses "Now()" when the resource is created that users cannot control or predict.
But since this is already in Beta, we still add the test coverage for it.
Also this change improves the user experience a little bit otherwise they don't now what value to give.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch. This doesn't feel like a spec field, because if I specify
ttl: 60s
what is the TTL value in 10 seconds? It seems like it should be 60s, because that is my desired state. But I suspect it will be 50s.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is exactly the problem!