Skip to content

Commit

Permalink
disable snapshots and gitops on embedded cluster (#4397)
Browse files Browse the repository at this point in the history
* disable snapshots on embedded cluster

also refactor to determine whether this is embedded cluster from an environment variable

* disable gitops in embedded cluster

* fix imports

* use the existing 'EMBEDDED_CLUSTER_ID' env var
  • Loading branch information
laverya authored Jan 25, 2024
1 parent 90a6319 commit bf57f45
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 50 deletions.
11 changes: 4 additions & 7 deletions pkg/embeddedcluster/helmvm_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/embeddedcluster/types"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/util"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -29,7 +30,9 @@ func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.Embedded
return nil, errors.Wrap(err, "failed to create metrics client")
}

toReturn := types.EmbeddedClusterNodes{}
toReturn := types.EmbeddedClusterNodes{
IsEmbeddedClusterEnabled: util.IsEmbeddedCluster(),
}

for _, node := range nodes.Items {
nodeMet, err := nodeMetrics(ctx, client, metricsClient, node)
Expand All @@ -40,12 +43,6 @@ func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.Embedded
toReturn.Nodes = append(toReturn.Nodes, *nodeMet)
}

isEmbeddedCluster, err := IsEmbeddedCluster(client)
if err != nil {
return nil, errors.Wrap(err, "is embeddedcluster")
}
toReturn.IsEmbeddedClusterEnabled = isEmbeddedCluster

isHA, err := IsHA(client)
if err != nil {
return nil, errors.Wrap(err, "is ha")
Expand Down
13 changes: 3 additions & 10 deletions pkg/embeddedcluster/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/replicatedhq/embedded-cluster-operator/api/v1beta1"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/store"
"github.com/replicatedhq/kots/pkg/util"
"k8s.io/client-go/kubernetes"
)

Expand All @@ -25,11 +26,7 @@ func MaybeStartClusterUpgrade(ctx context.Context, client kubernetes.Interface,
return nil
}

isEC, err := IsEmbeddedCluster(client)
if err != nil {
return fmt.Errorf("failed to check if embedded cluster is enabled: %w", err)
}
if !isEC {
if !util.IsEmbeddedCluster() {
return nil
}

Expand Down Expand Up @@ -58,11 +55,7 @@ func MaybeStartClusterUpgrade(ctx context.Context, client kubernetes.Interface,
// InitClusterState initializes the cluster state in the database. This should be called when the
// server launches.
func InitClusterState(ctx context.Context, client kubernetes.Interface, store store.Store) error {
isEC, err := IsEmbeddedCluster(client)
if err != nil {
return fmt.Errorf("failed to check if embedded cluster is enabled: %w", err)
}
if isEC {
if util.IsEmbeddedCluster() {
go watchClusterState(ctx, store)
return nil
}
Expand Down
23 changes: 0 additions & 23 deletions pkg/embeddedcluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-operator/api/v1beta1"
"github.com/replicatedhq/kots/pkg/k8sutil"
corev1 "k8s.io/api/core/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
Expand All @@ -29,28 +28,6 @@ func ReadConfigMap(client kubernetes.Interface) (*corev1.ConfigMap, error) {
return client.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
}

func IsEmbeddedCluster(clientset kubernetes.Interface) (bool, error) {
if clientset == nil {
return false, fmt.Errorf("clientset is nil")
}

configMapExists := false
_, err := ReadConfigMap(clientset)
if err == nil {
configMapExists = true
} else if kuberneteserrors.IsNotFound(err) {
configMapExists = false
} else if kuberneteserrors.IsUnauthorized(err) {
configMapExists = false
} else if kuberneteserrors.IsForbidden(err) {
configMapExists = false
} else if err != nil {
return false, fmt.Errorf("failed to get embedded cluster configmap: %w", err)
}

return configMapExists, nil
}

func IsHA(clientset kubernetes.Interface) (bool, error) {
return true, nil
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ func responseAppFromApp(a *apptypes.App) (*types.ResponseApp, error) {
return nil, errors.Wrap(err, "failed to check if snapshots is allowed")
}
allowSnapshots := s && license.Spec.IsSnapshotSupported
if allowSnapshots {
if util.IsEmbeddedCluster() {
allowSnapshots = false // snapshots are not allowed in embedded cluster installations today
}
}

isGitopsSupported := license.Spec.IsGitOpsSupported && !util.IsEmbeddedCluster() // gitops is not allowed in embedded cluster installations today

links, err := version.GetRealizedLinksFromAppSpec(a.ID, parentSequence)
if err != nil {
Expand Down Expand Up @@ -340,7 +347,7 @@ func responseAppFromApp(a *apptypes.App) (*types.ResponseApp, error) {
IsConfigurable: a.IsConfigurable,
UpdateCheckerSpec: a.UpdateCheckerSpec,
AutoDeploy: a.AutoDeploy,
IsGitOpsSupported: license.Spec.IsGitOpsSupported,
IsGitOpsSupported: isGitopsSupported,
IsIdentityServiceSupported: license.Spec.IsIdentityServiceSupported,
IsAppIdentityServiceSupported: isAppIdentityServiceSupported,
IsGeoaxisSupported: license.Spec.IsGeoaxisSupported,
Expand Down
5 changes: 2 additions & 3 deletions pkg/kotsadm/metadata.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package kotsadm

import (
"github.com/replicatedhq/kots/pkg/embeddedcluster"
"github.com/replicatedhq/kots/pkg/kotsadm/types"
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/util"
"k8s.io/client-go/kubernetes"
)

func GetMetadata(clientset kubernetes.Interface) types.Metadata {
isKurl, _ := kurl.IsKurl(clientset)
isEmbeddedCluster, _ := embeddedcluster.IsEmbeddedCluster(clientset)

metadata := types.Metadata{
IsAirgap: IsAirgap(),
IsKurl: isKurl,
IsEmbeddedCluster: isEmbeddedCluster,
IsEmbeddedCluster: util.IsEmbeddedCluster(),
}

return metadata
Expand Down
7 changes: 1 addition & 6 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@ func (o *Operator) DeployApp(appID string, sequence int64) (deployed bool, deplo
return false, errors.Wrap(err, "failed to apply status informers")
}

isEmbeddedCluster, err := embeddedcluster.IsEmbeddedCluster(o.k8sClientset)
if err != nil {
return false, errors.Wrap(err, "failed to check if this is an embedded cluster installation")
}

o.client.ApplyNamespacesInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces, imagePullSecrets)
o.client.ApplyHooksInformer(kotsKinds.KotsApplication.Spec.AdditionalNamespaces)

Expand All @@ -413,7 +408,7 @@ func (o *Operator) DeployApp(appID string, sequence int64) (deployed bool, deplo
}
deployed, err = o.client.DeployApp(deployArgs)
if err != nil {
if isEmbeddedCluster {
if util.IsEmbeddedCluster() {
go func() {
logger.Info("app deploy failed, starting cluster upgrade in the background")
err2 := embeddedcluster.MaybeStartClusterUpgrade(context.Background(), o.k8sClientset, o.store, kotsKinds.EmbeddedClusterConfig)
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func IsHelmManaged() bool {
return os.Getenv("IS_HELM_MANAGED") == "true"
}

func IsEmbeddedCluster() bool {
return os.Getenv("EMBEDDED_CLUSTER_ID") != ""
}

func GetValueFromMapPath(m interface{}, path []string) interface{} {
if len(path) == 0 {
return nil
Expand Down

0 comments on commit bf57f45

Please sign in to comment.