Skip to content

Commit

Permalink
Relocate constants declaration to common dir
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 8876cbd commit fda8877
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
14 changes: 14 additions & 0 deletions pkg/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ const (
WebhookAPIBucketService = WebhookAPIVersion + "/bucketsrv"
WebhookAPIUpdate = WebhookAPIVersion + "/update"
)

const (
// OperatorRuntimeK8s is the default runtime when no specific runtime is set
OperatorRuntimeK8s Runtime = "k8s"
// OperatorRuntimeEKS is the EKS runtime flag
OperatorRuntimeEKS Runtime = "EKS"
// OperatorRuntimeOpenshift is the Openshift runtime flag
OperatorRuntimeOpenshift Runtime = "OPENSHIFT"
// OperatorRuntimeRancher is the Rancher runtime flag
OperatorRuntimeRancher Runtime = "RANCHER"
)

// Runtime type to for Operator runtime
type Runtime string
3 changes: 2 additions & 1 deletion pkg/controller/certificates/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package certificates

import (
"context"
"github.com/minio/operator/pkg/common"
"github.com/minio/operator/pkg/controller"
"os"
"strings"
Expand Down Expand Up @@ -111,7 +112,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() == controller.OperatorRuntimeEKS {
if controller.GetOperatorRuntime() == common.OperatorRuntimeEKS {
csrSignerName = EKSCsrSignerName
return
}
Expand Down
33 changes: 10 additions & 23 deletions pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"crypto/tls"
"github.com/minio/operator/pkg/common"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -53,20 +54,6 @@ const (
DefaultOperatorImage = "minio/operator:v5.0.6"
)

const (
// OperatorRuntimeK8s is the default runtime when no specific runtime is set
OperatorRuntimeK8s Runtime = "k8s"
// OperatorRuntimeEKS is the EKS runtime flag
OperatorRuntimeEKS Runtime = "EKS"
// OperatorRuntimeOpenshift is the Openshift runtime flag
OperatorRuntimeOpenshift Runtime = "OPENSHIFT"
// OperatorRuntimeRancher is the Rancher runtime flag
OperatorRuntimeRancher Runtime = "RANCHER"
)

// Runtime type to for Operator runtime
type Runtime string

var serverCertsManager *xcerts.Manager

// rolloutRestartDeployment - executes the equivalent to kubectl rollout restart deployment
Expand Down Expand Up @@ -127,7 +114,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() == OperatorRuntimeOpenshift {
if 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 @@ -257,22 +244,22 @@ func getOperatorDeploymentName() string {

func GetOperatorRuntime() Runtime {
envString := os.Getenv(OperatorRuntimeEnv)
runtimeReturn := OperatorRuntimeK8s
runtimeReturn := common.OperatorRuntimeK8s
if envString != "" {
envString = strings.TrimSpace(envString)
envString = strings.ToUpper(envString)
switch envString {
case string(OperatorRuntimeEKS):
runtimeReturn = OperatorRuntimeEKS
case string(common.OperatorRuntimeEKS):
runtimeReturn = common.OperatorRuntimeEKS
break
case string(OperatorRuntimeOpenshift):
runtimeReturn = OperatorRuntimeEKS
case string(common.OperatorRuntimeOpenshift):
runtimeReturn = common.OperatorRuntimeEKS
break
case string(OperatorRuntimeRancher):
runtimeReturn = OperatorRuntimeRancher
case string(common.OperatorRuntimeRancher):
runtimeReturn = common.OperatorRuntimeRancher
break
default:
runtimeReturn = OperatorRuntimeK8s
runtimeReturn = common.OperatorRuntimeK8s
}
}
return runtimeReturn
Expand Down

0 comments on commit fda8877

Please sign in to comment.