fix that the InterpretDependency operation is absent in the validating webhook
Signed-off-by: hejunhua <jayfantasyhjh@gmail.com> fix e2e problem Signed-off-by: hejunhua <jayfantasyhjh@gmail.com> fix test case Signed-off-by: hejunhua <jayfantasyhjh@gmail.com>
This commit is contained in:
parent
bfd75b040c
commit
f229d97be9
|
@ -6,7 +6,7 @@ metadata:
|
||||||
webhooks:
|
webhooks:
|
||||||
- name: workloads.example.com
|
- name: workloads.example.com
|
||||||
rules:
|
rules:
|
||||||
- operations: [ "InterpretReplica","ReviseReplica","Retain","AggregateStatus", "InterpretHealth", "InterpretStatus" ]
|
- operations: [ "InterpretReplica","ReviseReplica","Retain","AggregateStatus", "InterpretHealth", "InterpretStatus", "InterpretDependency" ]
|
||||||
apiGroups: [ "workload.example.io" ]
|
apiGroups: [ "workload.example.io" ]
|
||||||
apiVersions: [ "v1alpha1" ]
|
apiVersions: [ "v1alpha1" ]
|
||||||
kinds: [ "Workload" ]
|
kinds: [ "Workload" ]
|
||||||
|
|
|
@ -47,6 +47,8 @@ func (e *workloadInterpreter) Handle(ctx context.Context, req interpreter.Reques
|
||||||
return e.responseWithExploreInterpretHealth(workload)
|
return e.responseWithExploreInterpretHealth(workload)
|
||||||
case configv1alpha1.InterpreterOperationInterpretStatus:
|
case configv1alpha1.InterpreterOperationInterpretStatus:
|
||||||
return e.responseWithExploreInterpretStatus(workload)
|
return e.responseWithExploreInterpretStatus(workload)
|
||||||
|
case configv1alpha1.InterpreterOperationInterpretDependency:
|
||||||
|
return e.responseWithExploreDependency(workload)
|
||||||
default:
|
default:
|
||||||
return interpreter.Errored(http.StatusBadRequest, fmt.Errorf("wrong request operation type: %s", req.Operation))
|
return interpreter.Errored(http.StatusBadRequest, fmt.Errorf("wrong request operation type: %s", req.Operation))
|
||||||
}
|
}
|
||||||
|
@ -63,6 +65,13 @@ func (e *workloadInterpreter) responseWithExploreReplica(workload *workloadv1alp
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *workloadInterpreter) responseWithExploreDependency(workload *workloadv1alpha1.Workload) interpreter.Response {
|
||||||
|
res := interpreter.Succeeded("")
|
||||||
|
res.Dependencies = []configv1alpha1.DependentObjectReference{{APIVersion: "v1", Kind: "ConfigMap",
|
||||||
|
Namespace: workload.Namespace, Name: workload.Spec.Template.Spec.Containers[0].EnvFrom[0].ConfigMapRef.Name}}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (e *workloadInterpreter) responseWithExploreReviseReplica(workload *workloadv1alpha1.Workload, req interpreter.Request) interpreter.Response {
|
func (e *workloadInterpreter) responseWithExploreReviseReplica(workload *workloadv1alpha1.Workload, req interpreter.Request) interpreter.Response {
|
||||||
wantedWorkload := workload.DeepCopy()
|
wantedWorkload := workload.DeepCopy()
|
||||||
wantedWorkload.Spec.Replicas = req.DesiredReplicas
|
wantedWorkload.Spec.Replicas = req.DesiredReplicas
|
||||||
|
|
|
@ -65,6 +65,7 @@ func (v *ValidatingAdmission) InjectDecoder(d *admission.Decoder) error {
|
||||||
var supportedInterpreterOperation = sets.NewString(
|
var supportedInterpreterOperation = sets.NewString(
|
||||||
string(configv1alpha1.InterpreterOperationAll),
|
string(configv1alpha1.InterpreterOperationAll),
|
||||||
string(configv1alpha1.InterpreterOperationInterpretReplica),
|
string(configv1alpha1.InterpreterOperationInterpretReplica),
|
||||||
|
string(configv1alpha1.InterpreterOperationInterpretDependency),
|
||||||
string(configv1alpha1.InterpreterOperationReviseReplica),
|
string(configv1alpha1.InterpreterOperationReviseReplica),
|
||||||
string(configv1alpha1.InterpreterOperationRetain),
|
string(configv1alpha1.InterpreterOperationRetain),
|
||||||
string(configv1alpha1.InterpreterOperationAggregateStatus),
|
string(configv1alpha1.InterpreterOperationAggregateStatus),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/rand"
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
|
@ -271,6 +272,50 @@ var _ = ginkgo.Describe("Resource interpreter webhook testing", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.Context("InterpreterOperation InterpretDependency testing", func() {
|
||||||
|
var configMapNamespace, configMapName string
|
||||||
|
|
||||||
|
ginkgo.BeforeEach(func() {
|
||||||
|
configMapNamespace = testNamespace
|
||||||
|
configMapName = configMapNamePrefix + rand.String(RandomStrLength)
|
||||||
|
|
||||||
|
workload.Spec.Template.Spec.Containers[0].EnvFrom = []corev1.EnvFromSource{{
|
||||||
|
ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||||
|
LocalObjectReference: corev1.LocalObjectReference{Name: configMapName},
|
||||||
|
}}}
|
||||||
|
// configmaps should be propagated automatically.
|
||||||
|
policy.Spec.PropagateDeps = true
|
||||||
|
|
||||||
|
cm := testhelper.NewConfigMap(configMapNamespace, configMapName, map[string]string{"RUN_ENV": "test"})
|
||||||
|
|
||||||
|
framework.CreateConfigMap(kubeClient, cm)
|
||||||
|
ginkgo.DeferCleanup(func() {
|
||||||
|
framework.RemoveConfigMap(kubeClient, configMapNamespace, configMapName)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("InterpretDependency testing", func() {
|
||||||
|
ginkgo.By("check if workload's dependency is interpreted", func() {
|
||||||
|
clusterNames := framework.ClusterNames()
|
||||||
|
gomega.Eventually(func(g gomega.Gomega) (int, error) {
|
||||||
|
var configmapNum int
|
||||||
|
for _, clusterName := range clusterNames {
|
||||||
|
clusterClient := framework.GetClusterClient(clusterName)
|
||||||
|
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())
|
||||||
|
if _, err := clusterClient.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{}); err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
g.Expect(err).NotTo(gomega.HaveOccurred())
|
||||||
|
}
|
||||||
|
configmapNum++
|
||||||
|
}
|
||||||
|
return configmapNum, nil
|
||||||
|
}, pollTimeout, pollInterval).Should(gomega.Equal(len(clusterNames)))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = framework.SerialDescribe("Resource interpreter customization testing", func() {
|
var _ = framework.SerialDescribe("Resource interpreter customization testing", func() {
|
||||||
|
|
|
@ -506,7 +506,7 @@ func NewClusterWithResource(name string, allocatable, allocating, allocated core
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWorkload will build a workload object.
|
// NewWorkload will build a workload object.
|
||||||
func NewWorkload(namespace string, name string) *workloadv1alpha1.Workload {
|
func NewWorkload(namespace, name string) *workloadv1alpha1.Workload {
|
||||||
podLabels := map[string]string{"app": "nginx"}
|
podLabels := map[string]string{"app": "nginx"}
|
||||||
|
|
||||||
return &workloadv1alpha1.Workload{
|
return &workloadv1alpha1.Workload{
|
||||||
|
|
Loading…
Reference in New Issue