Skip to content

Commit 2dd186b

Browse files
Merge pull request #285 from yithian/OSD-20487_1_revert_drain_feature_flag
OSD-20487 Revert "Add feature flag to enable certain clusters to drain worker nodes (#279)"
2 parents d3bb9b4 + be40998 commit 2dd186b

File tree

5 files changed

+119
-205
lines changed

5 files changed

+119
-205
lines changed

build/resources.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,6 @@ func createRole() *rbacv1.Role {
111111
Namespace: *namespace,
112112
},
113113
Rules: []rbacv1.PolicyRule{
114-
{
115-
APIGroups: []string{
116-
"",
117-
},
118-
Resources: []string{
119-
"configmaps",
120-
},
121-
Verbs: []string{
122-
"get",
123-
},
124-
},
125114
{
126115
APIGroups: []string{
127116
"",

build/selectorsyncset.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ objects:
4141
name: validation-webhook
4242
namespace: openshift-validation-webhook
4343
rules:
44-
- apiGroups:
45-
- ""
46-
resources:
47-
- configmaps
48-
verbs:
49-
- get
5044
- apiGroups:
5145
- ""
5246
resources:

pkg/webhooks/add_node.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
11
package webhooks
22

3-
import (
4-
"context"
5-
"log"
6-
7-
"github.com/openshift/managed-cluster-validating-webhooks/config"
8-
"github.com/openshift/managed-cluster-validating-webhooks/pkg/webhooks/node"
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
"k8s.io/client-go/kubernetes"
11-
"k8s.io/client-go/rest"
12-
)
13-
14-
const allowWorkerNodeCordonConfigMapName = "allow-worker-node-cordon"
3+
import "github.com/openshift/managed-cluster-validating-webhooks/pkg/webhooks/node"
154

165
func init() {
17-
cfg, err := rest.InClusterConfig()
18-
if err != nil {
19-
log.Println("failed to load config for feature flag, running node webhook without the feature flag")
20-
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
21-
return
22-
}
23-
24-
client, err := kubernetes.NewForConfig(cfg)
25-
if err != nil {
26-
log.Println("failed to build kube client for feature flag, running node webhook without the feature flag")
27-
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
28-
return
29-
}
30-
31-
if _, err := client.CoreV1().ConfigMaps(config.OperatorNamespace).Get(context.TODO(), allowWorkerNodeCordonConfigMapName, metav1.GetOptions{}); err != nil {
32-
// The Configmap does not exist or we ran into errors looking for it
33-
// Assume this feature flag should be off
34-
Register(node.WebhookName, func() Webhook { return node.NewWebhook(false) })
35-
return
36-
}
37-
38-
// The ConfigMap exists! Turn on the feature flag
39-
Register(node.WebhookName, func() Webhook { return node.NewWebhook(true) })
6+
Register(node.WebhookName, func() Webhook { return node.NewWebhook() })
407
}

pkg/webhooks/node/node.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ var (
4949

5050
// NodeWebhook protects various objects from unauthorized manipulation
5151
type NodeWebhook struct {
52-
scheme *runtime.Scheme
53-
allowCordonWorkers bool
52+
scheme *runtime.Scheme
5453
}
5554

5655
func (s *NodeWebhook) Doc() string {
@@ -136,14 +135,6 @@ func (s *NodeWebhook) authorized(request admissionctl.Request) admissionctl.Resp
136135

137136
//Checks for non-adminGroups non-ceeGroup non-adminGroups users
138137
if request.Kind.Kind == "Node" {
139-
// If the allowCordonWorkers feature flag is off - deny all node actions
140-
if !s.allowCordonWorkers {
141-
log.Info("Denying access to modify nodes")
142-
ret = admissionctl.Denied("Prevented from modifying Red Hat managed nodes. This is in an effort to prevent harmful actions that may cause unintended consequences or affect the stability of the cluster. If you have any questions about this, please reach out to Red Hat support at https://access.redhat.com/support")
143-
ret.UID = request.AdmissionRequest.UID
144-
return ret
145-
}
146-
147138
node := corev1.Node{}
148139
decoder, err := admission.NewDecoder(s.scheme)
149140
if err != nil {
@@ -217,9 +208,8 @@ func (s *NodeWebhook) SyncSetLabelSelector() metav1.LabelSelector {
217208
func (s *NodeWebhook) HypershiftEnabled() bool { return false }
218209

219210
// NewWebhook creates a new webhook
220-
func NewWebhook(allowCordonWorkers bool) *NodeWebhook {
211+
func NewWebhook() *NodeWebhook {
221212
return &NodeWebhook{
222-
scheme: runtime.NewScheme(),
223-
allowCordonWorkers: allowCordonWorkers,
213+
scheme: runtime.NewScheme(),
224214
}
225215
}

0 commit comments

Comments
 (0)