From 16945bc40dfb742732627b0db9726481ffcc024f Mon Sep 17 00:00:00 2001 From: pjuarezd Date: Wed, 12 Jul 2023 16:35:55 -0600 Subject: [PATCH] Relocate method to get runtime and gofmt Signed-off-by: pjuarezd --- pkg/common/const.go | 2 ++ pkg/controller/certificates/csr.go | 7 +++--- pkg/controller/operator.go | 38 ++++++------------------------ pkg/utils/utils.go | 25 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/pkg/common/const.go b/pkg/common/const.go index 411d22c7a51..2b1981693a3 100644 --- a/pkg/common/const.go +++ b/pkg/common/const.go @@ -26,6 +26,8 @@ const ( ) const ( + // OperatorRuntimeEnv tells us which runtime we have. (EKS, Rancher, OpenShift, etc...) + OperatorRuntimeEnv = "MINIO_OPERATOR_RUNTIME" // OperatorRuntimeK8s is the default runtime when no specific runtime is set OperatorRuntimeK8s Runtime = "k8s" // OperatorRuntimeEKS is the EKS runtime flag diff --git a/pkg/controller/certificates/csr.go b/pkg/controller/certificates/csr.go index b659004a335..9bcdf2e4680 100644 --- a/pkg/controller/certificates/csr.go +++ b/pkg/controller/certificates/csr.go @@ -16,12 +16,13 @@ package certificates import ( "context" - "github.com/minio/operator/pkg/common" - "github.com/minio/operator/pkg/controller" "os" "strings" "sync" + "github.com/minio/operator/pkg/common" + "github.com/minio/operator/pkg/utils" + certificatesV1 "k8s.io/api/certificates/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/discovery" @@ -112,7 +113,7 @@ func GetCSRSignerName(clientSet kubernetes.Interface) string { // get certificates using their CSRSignerName https://docs.aws.amazon.com/eks/latest/userguide/cert-signing.html if GetCertificatesAPIVersion(clientSet) == CSRV1 { // if the user specified the EKS runtime, no need to do the check - if controller.GetOperatorRuntime() == common.OperatorRuntimeEKS { + if utils.GetOperatorRuntime() == common.OperatorRuntimeEKS { csrSignerName = EKSCsrSignerName return } diff --git a/pkg/controller/operator.go b/pkg/controller/operator.go index 96cdd7a3985..871bd16021c 100644 --- a/pkg/controller/operator.go +++ b/pkg/controller/operator.go @@ -19,18 +19,18 @@ package controller import ( "context" "crypto/tls" + "net" + "net/http" + "time" + "github.com/minio/operator/pkg/common" + "github.com/minio/operator/pkg/utils" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "net" - "net/http" - "os" - "strings" - "time" miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2" xcerts "github.com/minio/pkg/certs" @@ -44,8 +44,7 @@ const ( CertPasswordEnv = "OPERATOR_CERT_PASSWD" // OperatorDeploymentNameEnv Env variable to specify a custom deployment name for Operator OperatorDeploymentNameEnv = "MINIO_OPERATOR_DEPLOYMENT_NAME" - // OperatorRuntimeEnv tells us which runtime we have. (EKS, Rancher, OpenShift, etc...) - OperatorRuntimeEnv = "MINIO_OPERATOR_RUNTIME" + // OperatorCATLSSecretName is the name of the secret for the operator CA OperatorCATLSSecretName = "operator-ca-tls" // DefaultDeploymentName is the default name of the operator deployment @@ -114,7 +113,7 @@ func (c *Controller) getTransport() *http.Transport { // These chunk of code is intended for OpenShift ONLY and it will help us trust the signer to solve issue: // https://github.com/minio/operator/issues/1412 - if GetOperatorRuntime() == common.OperatorRuntimeOpenshift { + if utils.GetOperatorRuntime() == common.OperatorRuntimeOpenshift { openShiftCATLSCert, err := c.kubeClientSet.CoreV1().Secrets("openshift-kube-controller-manager-operator").Get( context.Background(), "csr-signer", metav1.GetOptions{}) klog.Info("Checking if this is OpenShift Environment to append the certificates...") @@ -241,26 +240,3 @@ func (c *Controller) createBuckets(ctx context.Context, tenant *miniov2.Tenant, func getOperatorDeploymentName() string { return env.Get(OperatorDeploymentNameEnv, DefaultDeploymentName) } - -func GetOperatorRuntime() Runtime { - envString := os.Getenv(OperatorRuntimeEnv) - runtimeReturn := common.OperatorRuntimeK8s - if envString != "" { - envString = strings.TrimSpace(envString) - envString = strings.ToUpper(envString) - switch envString { - case string(common.OperatorRuntimeEKS): - runtimeReturn = common.OperatorRuntimeEKS - break - case string(common.OperatorRuntimeOpenshift): - runtimeReturn = common.OperatorRuntimeEKS - break - case string(common.OperatorRuntimeRancher): - runtimeReturn = common.OperatorRuntimeRancher - break - default: - runtimeReturn = common.OperatorRuntimeK8s - } - } - return runtimeReturn -} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index c852f67a596..695518f2984 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -18,6 +18,10 @@ package utils import ( "encoding/base64" + "os" + "strings" + + "github.com/minio/operator/pkg/common" "github.com/google/uuid" ) @@ -53,3 +57,24 @@ const ( ContextRequestRemoteAddr = key("request-remote-addr") ContextAuditKey = key("request-audit-entry") ) + +// GetOperatorRuntime Retrieves the runtime from env variable +func GetOperatorRuntime() common.Runtime { + envString := os.Getenv(common.OperatorRuntimeEnv) + runtimeReturn := common.OperatorRuntimeK8s + if envString != "" { + envString = strings.TrimSpace(envString) + envString = strings.ToUpper(envString) + switch envString { + case string(common.OperatorRuntimeEKS): + runtimeReturn = common.OperatorRuntimeEKS + case string(common.OperatorRuntimeOpenshift): + runtimeReturn = common.OperatorRuntimeEKS + case string(common.OperatorRuntimeRancher): + runtimeReturn = common.OperatorRuntimeRancher + default: + runtimeReturn = common.OperatorRuntimeK8s + } + } + return runtimeReturn +}