Skip to content

Commit

Permalink
Env variable to manually set which version of certificates api to use (
Browse files Browse the repository at this point in the history
…#1076)

env variable MINIO_OPERATOR_CERTIFICATES_VERSION

Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
  • Loading branch information
Alevsk authored Mar 30, 2022
1 parent 2384f82 commit ef07a67
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions pkg/controller/cluster/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const (
OperatorTLSCASecretName = "operator-ca-tls"
// DefaultDeploymentName is the default name of the operator deployment
DefaultDeploymentName = "minio-operator"
// OperatorCertificatesVersion is the ENV var to force the certificates api version to use.
OperatorCertificatesVersion = "MINIO_OPERATOR_CERTIFICATES_VERSION"
)

var errOperatorWaitForTLS = errors.New("waiting for Operator cert")
Expand All @@ -68,20 +70,32 @@ func isOperatorTLS() bool {
return (set && value == "on") || !set
}

func certificatesAPIVersion() (string, bool) {
return os.LookupEnv(OperatorCertificatesVersion)
}

var useCertificatesV1Beta1API bool

// getCertificatesAPIVersion chooses which certificates api version operator will use to generate certificates
func (c *Controller) getCertificatesAPIVersion() {
apiVersions, err := c.kubeClientSet.Discovery().ServerPreferredResources()
if err != nil {
panic(err)
}
for _, api := range apiVersions {
// if certificates v1beta1 is present operator will use that api by default
// based on: https://github.com/aws/containers-roadmap/issues/1604#issuecomment-1072660824
if api.GroupVersion == "certificates.k8s.io/v1beta1" {
useCertificatesV1Beta1API = true
break
version, _ := certificatesAPIVersion()
switch version {
case "v1":
useCertificatesV1Beta1API = false
case "v1beta1":
useCertificatesV1Beta1API = true
default:
apiVersions, err := c.kubeClientSet.Discovery().ServerPreferredResources()
if err != nil {
panic(err)
}
for _, api := range apiVersions {
// if certificates v1beta1 is present operator will use that api by default
// based on: https://github.com/aws/containers-roadmap/issues/1604#issuecomment-1072660824
if api.GroupVersion == "certificates.k8s.io/v1beta1" {
useCertificatesV1Beta1API = true
break
}
}
}
}
Expand Down

0 comments on commit ef07a67

Please sign in to comment.