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

FailurePolicy of PodMutatingWebhook turn to Fail #129

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions cloudprovider/alibabacloud/slb.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@
}

func (s *SlbPlugin) OnPodAdded(c client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, cperrors.PluginError) {
networkManager := utils.NewNetworkManager(pod, c)
networkConfig := networkManager.GetNetworkConfig()
sc := parseLbConfig(networkConfig)
err := c.Create(ctx, s.consSvc(sc, pod, c, ctx))
return pod, cperrors.ToPluginError(err, cperrors.ApiCallError)
return pod, nil

Check warning on line 123 in cloudprovider/alibabacloud/slb.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/alibabacloud/slb.go#L123

Added line #L123 was not covered by tests
}

func (s *SlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, cperrors.PluginError) {
Expand Down
7 changes: 5 additions & 2 deletions cloudprovider/kubernetes/hostPort.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@
}

func (hpp *HostPortPlugin) OnPodAdded(c client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, errors.PluginError) {
log.Infof("Receiving pod %s/%s ADD Operation", pod.GetNamespace(), pod.GetName())

Check warning on line 73 in cloudprovider/kubernetes/hostPort.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/kubernetes/hostPort.go#L73

Added line #L73 was not covered by tests
podNow := &corev1.Pod{}
err := c.Get(ctx, types.NamespacedName{
Namespace: pod.GetNamespace(),
Name: pod.GetName(),
}, podNow)
// There is a pod with same ns/name exists in cluster, do not allocate
if err == nil {
return pod, nil
log.Infof("There is a pod with same ns/name(%s/%s) exists in cluster, do not allocate", pod.GetNamespace(), pod.GetName())
return pod, errors.NewPluginError(errors.InternalError, "There is a pod with same ns/name exists in cluster")

Check warning on line 81 in cloudprovider/kubernetes/hostPort.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/kubernetes/hostPort.go#L80-L81

Added lines #L80 - L81 were not covered by tests
}
if !k8serrors.IsNotFound(err) {
return pod, errors.NewPluginError(errors.ApiCallError, err.Error())
Expand Down Expand Up @@ -118,6 +119,7 @@
}

func (hpp *HostPortPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, errors.PluginError) {
log.Infof("Receiving pod %s/%s UPDATE Operation", pod.GetNamespace(), pod.GetName())

Check warning on line 122 in cloudprovider/kubernetes/hostPort.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/kubernetes/hostPort.go#L122

Added line #L122 was not covered by tests
node := &corev1.Node{}
err := c.Get(ctx, types.NamespacedName{
Name: pod.Spec.NodeName,
Expand Down Expand Up @@ -183,6 +185,7 @@
}

func (hpp *HostPortPlugin) OnPodDeleted(c client.Client, pod *corev1.Pod, ctx context.Context) errors.PluginError {
log.Infof("Receiving pod %s/%s DELETE Operation", pod.GetNamespace(), pod.GetName())

Check warning on line 188 in cloudprovider/kubernetes/hostPort.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/kubernetes/hostPort.go#L188

Added line #L188 was not covered by tests
if _, ok := hpp.podAllocated[pod.GetNamespace()+"/"+pod.GetName()]; !ok {
return nil
}
Expand Down
17 changes: 0 additions & 17 deletions cloudprovider/kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,6 @@ func (i IngressPlugin) Init(client client.Client, options cloudprovider.CloudPro
}

func (i IngressPlugin) OnPodAdded(c client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, cperrors.PluginError) {
networkManager := utils.NewNetworkManager(pod, c)
conf := networkManager.GetNetworkConfig()
ic, err := parseIngConfig(conf, pod)
if err != nil {
return pod, cperrors.NewPluginError(cperrors.ParameterError, err.Error())
}

err = c.Create(ctx, consSvc(ic, pod, c, ctx))
if err != nil {
return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error())
}

err = c.Create(ctx, consIngress(ic, pod, c, ctx))
if err != nil {
return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error())
}

return pod, nil
}

Expand Down
6 changes: 1 addition & 5 deletions cloudprovider/volcengine/clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,8 @@
}

func (c *ClbPlugin) OnPodAdded(client client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, cperrors.PluginError) {
networkManager := utils.NewNetworkManager(pod, client)
networkConfig := networkManager.GetNetworkConfig()
sc := parseLbConfig(networkConfig)
err := client.Create(ctx, c.consSvc(sc, pod, client, ctx))
return pod, cperrors.ToPluginError(err, cperrors.ApiCallError)
return pod, nil
}

Check warning on line 132 in cloudprovider/volcengine/clb.go

View check run for this annotation

Codecov / codecov/patch

cloudprovider/volcengine/clb.go#L131-L132

Added lines #L131 - L132 were not covered by tests

func (c *ClbPlugin) OnPodUpdated(client client.Client, pod *corev1.Pod, ctx context.Context) (*corev1.Pod, cperrors.PluginError) {
networkManager := utils.NewNetworkManager(pod, client)
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/mutating_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func getPodFromRequest(req admission.Request, decoder *admission.Decoder) (*core

func getAdmissionResponse(req admission.Request, result patchResult) admission.Response {
if result.err != nil {
return admission.Allowed(result.err.Error())
return admission.Denied(result.err.Error())
}
if req.Operation == admissionv1.Delete {
return admission.Allowed("delete successfully")
Expand Down
14 changes: 12 additions & 2 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"flag"
"fmt"
gamekruiseiov1alpha1 "github.com/openkruise/kruise-game/apis/v1alpha1"
manager2 "github.com/openkruise/kruise-game/cloudprovider/manager"
"github.com/openkruise/kruise-game/pkg/webhook/util/generator"
"github.com/openkruise/kruise-game/pkg/webhook/util/writer"
Expand Down Expand Up @@ -247,12 +248,12 @@ func getValidatingWebhookConf(dnsName string, caBundle []byte) []admissionregist

func getMutatingWebhookConf(dnsName string, caBundle []byte) []admissionregistrationv1.MutatingWebhook {
sideEffectClassNone := admissionregistrationv1.SideEffectClassNone
ignore := admissionregistrationv1.Ignore
fail := admissionregistrationv1.Fail
return []admissionregistrationv1.MutatingWebhook{
{
Name: dnsName,
SideEffects: &sideEffectClassNone,
FailurePolicy: &ignore,
FailurePolicy: &fail,
AdmissionReviewVersions: []string{"v1", "v1beta1"},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
Service: &admissionregistrationv1.ServiceReference{
Expand All @@ -272,6 +273,15 @@ func getMutatingWebhookConf(dnsName string, caBundle []byte) []admissionregistra
},
},
},
ObjectSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: gamekruiseiov1alpha1.GameServerOwnerGssKey,
Operator: metav1.LabelSelectorOpExists,
Values: []string{},
},
},
},
},
}
}
Loading