Skip to content

Commit c30e14d

Browse files
authored
Merge pull request #3076 from XiShanYongYe-Chang/automated-cherry-pick-of-#3052-upstream-release-1.3
Automated cherry pick of #3052: fix that the InterpretDependency operation is absent in the
2 parents 8821b76 + ff4b977 commit c30e14d

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

examples/customresourceinterpreter/webhook-configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
webhooks:
77
- name: workloads.example.com
88
rules:
9-
- operations: [ "InterpretReplica","ReviseReplica","Retain","AggregateStatus", "InterpretHealth", "InterpretStatus" ]
9+
- operations: [ "InterpretReplica","ReviseReplica","Retain","AggregateStatus", "InterpretHealth", "InterpretStatus", "InterpretDependency" ]
1010
apiGroups: [ "workload.example.io" ]
1111
apiVersions: [ "v1alpha1" ]
1212
kinds: [ "Workload" ]

examples/customresourceinterpreter/webhook/app/workloadwebhook.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func (e *workloadInterpreter) Handle(ctx context.Context, req interpreter.Reques
4747
return e.responseWithExploreInterpretHealth(workload)
4848
case configv1alpha1.InterpreterOperationInterpretStatus:
4949
return e.responseWithExploreInterpretStatus(workload)
50+
case configv1alpha1.InterpreterOperationInterpretDependency:
51+
return e.responseWithExploreDependency(workload)
5052
default:
5153
return interpreter.Errored(http.StatusBadRequest, fmt.Errorf("wrong request operation type: %s", req.Operation))
5254
}
@@ -63,6 +65,13 @@ func (e *workloadInterpreter) responseWithExploreReplica(workload *workloadv1alp
6365
return res
6466
}
6567

68+
func (e *workloadInterpreter) responseWithExploreDependency(workload *workloadv1alpha1.Workload) interpreter.Response {
69+
res := interpreter.Succeeded("")
70+
res.Dependencies = []configv1alpha1.DependentObjectReference{{APIVersion: "v1", Kind: "ConfigMap",
71+
Namespace: workload.Namespace, Name: workload.Spec.Template.Spec.Containers[0].EnvFrom[0].ConfigMapRef.Name}}
72+
return res
73+
}
74+
6675
func (e *workloadInterpreter) responseWithExploreReviseReplica(workload *workloadv1alpha1.Workload, req interpreter.Request) interpreter.Response {
6776
wantedWorkload := workload.DeepCopy()
6877
wantedWorkload.Spec.Replicas = req.DesiredReplicas

pkg/webhook/configuration/validating.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (v *ValidatingAdmission) InjectDecoder(d *admission.Decoder) error {
6565
var supportedInterpreterOperation = sets.NewString(
6666
string(configv1alpha1.InterpreterOperationAll),
6767
string(configv1alpha1.InterpreterOperationInterpretReplica),
68+
string(configv1alpha1.InterpreterOperationInterpretDependency),
6869
string(configv1alpha1.InterpreterOperationReviseReplica),
6970
string(configv1alpha1.InterpreterOperationRetain),
7071
string(configv1alpha1.InterpreterOperationAggregateStatus),

test/e2e/resourceinterpreter_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
"github.com/onsi/ginkgo/v2"
1010
"github.com/onsi/gomega"
11+
corev1 "k8s.io/api/core/v1"
12+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1113
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1214
"k8s.io/apimachinery/pkg/util/rand"
1315
"k8s.io/apimachinery/pkg/util/wait"
@@ -271,4 +273,48 @@ var _ = ginkgo.Describe("Resource interpreter webhook testing", func() {
271273
})
272274
})
273275
})
276+
277+
ginkgo.Context("InterpreterOperation InterpretDependency testing", func() {
278+
var configMapNamespace, configMapName string
279+
280+
ginkgo.BeforeEach(func() {
281+
configMapNamespace = testNamespace
282+
configMapName = configMapNamePrefix + rand.String(RandomStrLength)
283+
284+
workload.Spec.Template.Spec.Containers[0].EnvFrom = []corev1.EnvFromSource{{
285+
ConfigMapRef: &corev1.ConfigMapEnvSource{
286+
LocalObjectReference: corev1.LocalObjectReference{Name: configMapName},
287+
}}}
288+
// configmaps should be propagated automatically.
289+
policy.Spec.PropagateDeps = true
290+
291+
cm := testhelper.NewConfigMap(configMapNamespace, configMapName, map[string]string{"RUN_ENV": "test"})
292+
293+
framework.CreateConfigMap(kubeClient, cm)
294+
ginkgo.DeferCleanup(func() {
295+
framework.RemoveConfigMap(kubeClient, configMapNamespace, configMapName)
296+
})
297+
})
298+
299+
ginkgo.It("InterpretDependency testing", func() {
300+
ginkgo.By("check if workload's dependency is interpreted", func() {
301+
clusterNames := framework.ClusterNames()
302+
gomega.Eventually(func(g gomega.Gomega) (int, error) {
303+
var configmapNum int
304+
for _, clusterName := range clusterNames {
305+
clusterClient := framework.GetClusterClient(clusterName)
306+
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())
307+
if _, err := clusterClient.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{}); err != nil {
308+
if apierrors.IsNotFound(err) {
309+
continue
310+
}
311+
g.Expect(err).NotTo(gomega.HaveOccurred())
312+
}
313+
configmapNum++
314+
}
315+
return configmapNum, nil
316+
}, pollTimeout, pollInterval).Should(gomega.Equal(len(clusterNames)))
317+
})
318+
})
319+
})
274320
})

test/helper/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func NewClusterWithResource(name string, allocatable, allocating, allocated core
496496
}
497497

498498
// NewWorkload will build a workload object.
499-
func NewWorkload(namespace string, name string) *workloadv1alpha1.Workload {
499+
func NewWorkload(namespace, name string) *workloadv1alpha1.Workload {
500500
podLabels := map[string]string{"app": "nginx"}
501501

502502
return &workloadv1alpha1.Workload{

0 commit comments

Comments
 (0)