Skip to content

Commit

Permalink
fix: deployment render should only mutate workloads created by yurtap… (
Browse files Browse the repository at this point in the history
openyurtio#1974)

* fix: deployment render should only mutate workloads created by yurtappset v1alpha1
  • Loading branch information
vie-serendipity authored Mar 13, 2024
1 parent 34b14cc commit e33a217
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func (webhook *DeploymentRenderHandler) Default(ctx context.Context, obj runtime
var instance client.Object
switch app.Kind {
case "YurtAppSet":
if app.APIVersion != v1alpha1.SchemeGroupVersion.String() {
return nil
}
instance = &v1alpha1.YurtAppSet{}
case "YurtAppDaemon":
instance = &v1alpha1.YurtAppDaemon{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,45 @@ var defaultAppDaemon = &v1alpha1.YurtAppDaemon{
},
}

var deploymentByYasv1beta1 = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
Namespace: "default",
OwnerReferences: []metav1.OwnerReference{{
APIVersion: "apps.openyurt.io/v1beta1",
Kind: "YurtAppSet",
Name: "yurtappset-patch",
}},
Labels: map[string]string{
"apps.openyurt.io/pool-name": "nodepool-test",
},
},
Status: appsv1.DeploymentStatus{},
Spec: appsv1.DeploymentSpec{
Replicas: &replica,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "test",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "test",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "nginx",
Image: "nginx",
},
},
},
},
},
}

var defaultDeployment = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
Expand Down Expand Up @@ -328,6 +367,9 @@ func TestDeploymentRenderHandler_Default(t *testing.T) {
if err := webhook.Default(context.TODO(), daemonDeployment); err != nil {
t.Fatal(err)
}
if err := webhook.Default(context.TODO(), deploymentByYasv1beta1); err != nil {
t.Fatal(err)
}
})
}
}

0 comments on commit e33a217

Please sign in to comment.