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

Detect different versions of cert-manager #1546

Merged
merged 9 commits into from Jun 4, 2020

Conversation

ANeumann82
Copy link
Member

Detect different versions of cert-manager and install the correct CRDs

  • Supports cert-manager 0.10.1 and 0.11.0+
  • kudo init --dry-run --output yaml uses a default with the newest cert-manager API
  • Removed the warning and check for a cert-manager deployment, as we not really depend on the exact version
  • Had to make the whole setup/installation stateful so we can hold the required cert-manager versions, but this may come in handy later if we expand the installation

Signed-off-by: Andreas Neumann aneumann@mesosphere.com

… ones

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

Lgtm. I'd prefer a cert-manager group -> API mapping (make handling future changes easier)

@@ -154,10 +154,12 @@ func (initCmd *initCmd) run() error {
}
}

installer := setup.NewInstaller(opts, initCmd.crdOnly)
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't know why crdOnly is not part of the opts. But that's another story

}

const (
certManagerAPIVersion = "v1alpha2"
certManagerControllerVersion = "v0.12.0"
certManagerOldGroup = "certmanager.k8s.io"
Copy link
Contributor

Choose a reason for hiding this comment

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

What about a group -> api mapping instead like?

certManagerGroupAPI := map[string]string{
  "v1alpha1": "certmanager.k8s.io",
  "v1alpha2": "cert-manager.io",
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not necessarily a map... It might be a map of lists:

certManagerAPIs := map[string][]string{
  "certmanager.k8s.io": []string{ "v1alpha1"},
  "cert-manager.io": []string{ "v1alpha1", "v1alpha2", "v1alpha3" },
}

(at least I think "cert-manager.io" has "v1alpha1" as well in some version, it certainly has v1alpha2 and v1alpha3)

Copy link
Contributor

Choose a reason for hiding this comment

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

So even easier to check all permutatations 👍

Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

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

Awesome! 🚢

Copy link
Member

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

This is incomplete and I would prefer some refactor for readability.

The incomplete element is:

  1. webhook.goL225 has a "warning" that is still showing up.. which has multiple issues: first we should NOT print warning messages which use the wording "failed". second, if we successfully install for v1 (while preferring v2) it should NOT print any warnings... (unless verbose clog is > 0). If we are deprecating support and provide a warning that indicates that... that seems cool.

output of init

go run cmd/kubectl-kudo/main.go init --wait
$KUDO_HOME has been configured at /Users/kensipe/.kudo
Warnings                                                                                           
failed to get cert-manager deployment in namespace cert-manager. Make sure cert-manager is running.
✅ installed crds
✅ installed namespace
✅ installed service account
✅ installed webhook
✅ installed kudo controller
⌛Waiting for KUDO controller to be ready in your cluster...

The Warning section should not exist IMO.

Also... our docs for uninstall are: https://kudo.dev/docs/runbooks/admin/remove-kudo.html

our output for uninstall is:

 go run cmd/kubectl-kudo/main.go init --dry-run --output yaml | kubectl delete -f -
customresourcedefinition.apiextensions.k8s.io "operators.kudo.dev" deleted
customresourcedefinition.apiextensions.k8s.io "operatorversions.kudo.dev" deleted
customresourcedefinition.apiextensions.k8s.io "instances.kudo.dev" deleted
namespace "kudo-system" deleted
serviceaccount "kudo-manager" deleted
clusterrolebinding.rbac.authorization.k8s.io "kudo-manager-rolebinding" deleted
mutatingwebhookconfiguration.admissionregistration.k8s.io "kudo-manager-instance-admission-webhook-config" deleted
service "kudo-controller-manager-service" deleted
statefulset.apps "kudo-controller-manager" deleted
unable to recognize "STDIN": no matches for kind "Issuer" in version "cert-manager.io/v1alpha2"
unable to recognize "STDIN": no matches for kind "Certificate" in version "cert-manager.io/v1alpha2"

we should not try to output issuer and cert if they are not requested.... and/or we need doc updates for users to understand this message.

}
if k.certManagerGroup != "" {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

this is odd combo of funcs and state... this function needs intimate knowledge of the detectCertManagerCRD func... which is odd..

there is a lot of refactor here IMO...

  1. detectCertManagerVersion seems like a very specific func name when it could be a generic kube func
  2. we should prefer the return of values rather than the change of values passed by ref. It would be much easy to read and reason about IMO
  3. it also seems strange that error handling is happening in 2 different ways... we have the return of an err and an adding of an error to the "result" which returns a nil. It isn't clear when one vs the other is appropriate.

@kensipe
Copy link
Member

kensipe commented Jun 3, 2020

as I'm looking deeper at code... I don't understand why we do all the checks on the cert-man... if can detect we have a deployment... why check for a container. and then why check for health? This is a moment in time... just because it isn't healthy at this moment... doesn't mean it won't eventually be... and just because it is healthy in this moment... doesn't mean it will be when needed? this seems like a lot of extra and brittle code for questionable value.

Signed-off-by: Ken Sipe <kensipe@gmail.com>
func (k *KudoWebHook) resourcesWithCertManager() []runtime.Object {
// We have to fall back to a default here as for a dry-run we can't detect the actual version of a cluster
k.issuer = issuer(k.opts.Namespace, certManagerNewGroup, certManagerAPIVersions[0])
k.certificate = certificate(k.opts.Namespace, certManagerNewGroup, certManagerAPIVersions[0])
Copy link
Member

Choose a reason for hiding this comment

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

these lines of code... can we get rid of them? Issuer and Certificate do NOT seem to be installed with --unsafe-self-signed-webhook-ca. it is unclear if they are ever used... other than --dry-run -o yaml. If we have a need to provide details around issuer and cert for this model of installation we should do it. If these are needed for a specific style of installation we need to talk about it.

These should be complete removed which will resolve the remaining blocking issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, they are not used when --unsafe-self-signed-webhook-ca is used. Issuer and Certificate are created when we don't use a self-signed-ca.

With this refactoring they are detected in the preInstallVerify step and the correct version of Issuer and Certificate for the installed cert-manager are created.

They are then applied in the Install step.

The problem with resources is that this step currently does not use the preInstallVerify step, and it usually doesn't even have a client initialized because it doesn't need an existing K8s cluster at all. Now that we need to detect the correct cert-manager version, we may have to do that. Maybe that's not a bad thing...

@kensipe
Copy link
Member

kensipe commented Jun 3, 2020

I pushed a version of cert-man detection that works for konvoy and should work for any distro that provides the standard label of app=cert-manager for the certman deployment.

The remaining blocking issue is around the kinds Certification and Issuer. I guess I don't understand when and why they are used. I spent significant time around this today... it doesn't look like they are used if init on a cluster with a certman... nor are they used on a cluster with an --unsafe-self-signed-webhook-ca. It looks like they are only provided for dry-run with yaml output... why? It seems like we should remove them... I wanted to discuss first.

@ANeumann82
Copy link
Member Author

I pushed a version of cert-man detection that works for konvoy and should work for any distro that provides the standard label of app=cert-manager for the certman deployment.

Yeah, I like that. And I agree that we probably can get rid of the additional checks for cert-manager health, etc.

The remaining blocking issue is around the kinds Certification and Issuer. I guess I don't understand when and why they are used. I spent significant time around this today... it doesn't look like they are used if init on a cluster with a certman... nor are they used on a cluster with an --unsafe-self-signed-webhook-ca. It looks like they are only provided for dry-run with yaml output... why? It seems like we should remove them... I wanted to discuss first.

The cert is used here:

"cert-manager.io/inject-ca-from": fmt.Sprintf("%s/kudo-webhook-server-certificate", ns),

It's either this or the self-signed-webhook-ca...

ANeumann82 and others added 6 commits June 4, 2020 14:01
Refactoring of webhook cert-manager detection

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
# Conflicts:
#	pkg/kudoctl/cmd/testdata/deploy-kudo-webhook.yaml.golden
…r error message when no cluster is reachable

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Ken Sipe <kensipe@gmail.com>
Copy link
Member

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

/lgtm

really nice work!

@kensipe kensipe merged commit f8d96bd into master Jun 4, 2020
@kensipe kensipe deleted the an/allow-older-cert-manager branch June 4, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants