Skip to content

Commit

Permalink
move utils and add setup ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
shaofan-hs committed Aug 17, 2023
1 parent fd63316 commit 73398cc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
22 changes: 22 additions & 0 deletions pkg/controllers/add_ruleset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2023 The KusionStack Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"kusionstack.io/kafed/pkg/controllers/ruleset"
)

func init() {
AddToManagerFuncs = append(AddToManagerFuncs, ruleset.RuleSetManager().SetupRuleSetController)
}
10 changes: 9 additions & 1 deletion pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@
package utils

import (
"encoding/json"

"sigs.k8s.io/controller-runtime/pkg/client"

"kusionstack.io/kafed/apis/apps/v1alpha1"
)

func ControlledByKafed(obj client.Object) bool {
// DumpJSON returns the JSON encoding
func DumpJSON(o interface{}) string {
j, _ := json.Marshal(o)
return string(j)
}

func ControlledByPodOpsLifecycle(obj client.Object) bool {
if obj == nil || obj.GetLabels() == nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/server/generic/pod/opslifecycle/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
if !utils.ControlledByKafed(newPod) || operation != admissionv1.Update {
if !utils.ControlledByPodOpsLifecycle(newPod) || operation != admissionv1.Update {
return nil
}
addReadinessGates(newPod, v1alpha1.ReadinessGatePodServiceReady)
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/server/generic/pod/opslifecycle/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func (lc *OpsLifecycle) Validating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
if !utils.ControlledByKafed(newPod) {
if !utils.ControlledByPodOpsLifecycle(newPod) {
return nil
}
expectedLabels := make(map[string]struct{})
Expand Down
25 changes: 0 additions & 25 deletions pkg/webhook/utils/json.go

This file was deleted.

0 comments on commit 73398cc

Please sign in to comment.