Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement 'IsHelmVM' function based on presence of configmap #4064

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion pkg/helmvm/util.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
package helmvm

import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"

kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

const configMapName = "embedded-cluster-config"
const configMapNamespace = "kube-system"

// ReadConfigMap will read the embedded cluster config from a configmap
func ReadConfigMap(client kubernetes.Interface) (*corev1.ConfigMap, error) {
return client.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
}

func IsHelmVM(clientset kubernetes.Interface) (bool, error) {
return false, nil
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) {
Expand Down
Loading