Skip to content

Commit

Permalink
Relocate method to get runtime and gofmt
Browse files Browse the repository at this point in the history
Signed-off-by: pjuarezd <pjuarezd@users.noreply.github.com>
  • Loading branch information
pjuarezd committed Jul 12, 2023
1 parent 11c64b1 commit 16945bc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
2 changes: 2 additions & 0 deletions pkg/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/certificates/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
38 changes: 7 additions & 31 deletions pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package utils

import (
"encoding/base64"
"os"
"strings"

"github.com/minio/operator/pkg/common"

"github.com/google/uuid"
)
Expand Down Expand Up @@ -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
}

0 comments on commit 16945bc

Please sign in to comment.