-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathadd_node.go
More file actions
40 lines (33 loc) · 1.36 KB
/
add_node.go
File metadata and controls
40 lines (33 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package webhooks
import (
"context"
"log"
"github.com/openshift/managed-cluster-validating-webhooks/config"
"github.com/openshift/managed-cluster-validating-webhooks/pkg/webhooks/node"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
const allowWorkerNodeCordonConfigMapName = "allow-worker-node-cordon"
func init() {
cfg, err := rest.InClusterConfig()
if err != nil {
log.Println("failed to load config for feature flag, running node webhook without the feature flag")
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
return
}
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
log.Println("failed to build kube client for feature flag, running node webhook without the feature flag")
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
return
}
if _, err := client.CoreV1().ConfigMaps(config.OperatorNamespace).Get(context.TODO(), allowWorkerNodeCordonConfigMapName, metav1.GetOptions{}); err != nil {
// The Configmap does not exist or we ran into errors looking for it
// Assume this feature flag should be off
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
return
}
// The ConfigMap exists! Turn on the feature flag
Register(node.WebhookName, func() Webhook { return node.NewWebhook(true) })
}