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

Make some recently required bool parameters optional #650

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

tvoran
Copy link
Member

@tvoran tvoran commented Mar 12, 2024

(Just putting this up as an option to address #631 if we wish.)

Makes some currently required bool parameters optional, but keeps the default of false, so that the value can effectively be set to false in k8s storage. The secret destination options were added in v0.5.0.

I was able to duplicate the upgrade error in #631 on OpenShift outside of OperatorHub with operator-sdk run bundle... and operator-sdk run bundle-upgrade..., which would fail when going from v0.4.3 to v0.5.x, but succeed when going from v0.4.3 to these changes.

Details for posterity:
$ oc new-project vault-secrets-operator

$ operator-sdk run bundle -n vault-secrets-operator registry.connect.redhat.com/hashicorp/vault-secrets-operator-bundle:0.4.3

# deploy a VaultStaticSecret setup
...

# upgrade the operator
$ operator-sdk run bundle-upgrade -n vault-secrets-operator registry.connect.redhat.com/hashicorp/vault-secrets-operator-bundle:0.5.1

# ^ this will eventually timeout, with an error like this in the status of the subscription:
$ kubectl get subscription -n vault-secrets-operator vault-secrets-operator-v0-4-3-sub -o yaml
...
    message: 'error validating existing CRs against new CRD''s schema for "vaultstaticsecrets.secrets.hashicorp.com":
      error validating custom resource against new schema for VaultStaticSecret tenant-1/static-demo:
      [].spec.destination.overwrite: Required value'
...

# Build a bundle from this branch
$ export PREVIOUS_VERSION=v0.5.1
$ export TEST_VERSION=0.5.2-test-olm-upgrade
$ make ci-build ci-docker-build-ubi VERSION=${TEST_VERSION?}
$ docker tag hashicorp/vault-secrets-operator:${TEST_VERSION?}-ubi <docker-repo>:${TEST_VERSION?}-ubi
$ docker push <docker-repo>:${TEST_VERSION?}-ubi

$ make bundle IMG=<docker-repo>:${TEST_VERSION?} IMG_UBI=<docker-repo>:${TEST_VERSION?}-ubi VERSION=${TEST_VERSION?} USE_IMAGE_DIGESTS=true
$ make bundle-build BUNDLE_IMG=<docker-repo>-bundle:${TEST_VERSION?}
$ docker push <docker-repo>-bundle:${TEST_VERSION?}

# start over from the beginning, but do the bundle-upgrade with this branch, and the upgrade passes
...
$ operator-sdk run bundle-upgrade -n vault-secrets-operator docker.io/<docker-repo>-bundle:0.5.2-test-olm-upgrade

Closes #631

But keep the default of `false`, so that the value can effectively be
set to `false` in k8s storage. VaultConnection's skipTLSVerify was
set to required in v0.4.3, and the secret destination options were
added in v0.5.0.
@tvoran tvoran requested a review from a team as a code owner March 12, 2024 07:06
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm supportive of this approach 👍 it always looked a bit wrong to me that these parameters were marked as required

Copy link
Collaborator

@benashz benashz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should revert the change made to SkipTLSVerify, after that +1

@@ -22,7 +22,7 @@ type VaultConnectionSpec struct {
CACertSecretRef string `json:"caCertSecretRef,omitempty"`
// SkipTLSVerify for TLS connections.
// +kubebuilder:default=false
SkipTLSVerify bool `json:"skipTLSVerify"`
SkipTLSVerify bool `json:"skipTLSVerify,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one we want to keep as-is. We made this change under #527 - to avoid an issue with Rancher.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can certainly do that, especially since this has been in place since v0.4.3.

FWIW in my testing this behaves the same with or without omitempty when there's a default set. If the parameter is set to true/false in the CRD spec it comes back on a get. And if the parameter is unspecified it comes back as false on a get. Which I think satisfies #527 and #278.

@benashz
Copy link
Collaborator

benashz commented Mar 12, 2024

I'm supportive of this approach 👍 it always looked a bit wrong to me that these parameters were marked as required

@tomhjp - yeah its unfortunate that fields with defaults are not excluded from the set of required fields, or that the validators do not take defaults into account.

@benashz benashz added this to the v0.5.2 milestone Mar 12, 2024
@tvoran tvoran merged commit 716db60 into main Mar 13, 2024
43 checks passed
@tvoran tvoran deleted the VAULT-24553/unbreak-schema-changes-for-olm branch March 13, 2024 06:03
Comment on lines +171 to +173
skips:
- vault-secrets-operator.v0.5.0
- vault-secrets-operator.v0.5.1
Copy link
Member Author

@tvoran tvoran Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of these I think we'll want to use PREVIOUS_VERSION=v0.4.3 with make bundle at release time:

make bundle VERSION=${LATEST_TAG//v} USE_IMAGE_DIGESTS=true PREVIOUS_VERSION=v0.4.3

So that the resulting build/bundle/manifests/vault-secrets-operator.clusterserviceversion.yaml comes out like this:

  skips:
    - vault-secrets-operator.v0.5.0
    - vault-secrets-operator.v0.5.1
  version: 0.5.2
  replaces: vault-secrets-operator.v0.4.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking changes to v1beta1 VaultStaticSecret and VaultConnection CRDs cause failed upgrades after v0.5.0
3 participants