Merge pull request #2716 from chaunceyjiang/ut
Add UT for imageoverride
This commit is contained in:
commit
8d5f56b8b3
|
|
@ -15015,7 +15015,7 @@
|
||||||
"default": ""
|
"default": ""
|
||||||
},
|
},
|
||||||
"predicate": {
|
"predicate": {
|
||||||
"description": "Predicate filters images before applying the rule.\n\nDefaults to nil, in that case, the system will automatically detect image fields if the resource type is Pod, ReplicaSet, Deployment or StatefulSet by following rule:\n - Pod: spec/containers/\u003cN\u003e/image\n - ReplicaSet: spec/template/spec/containers/\u003cN\u003e/image\n - Deployment: spec/template/spec/containers/\u003cN\u003e/image\n - StatefulSet: spec/template/spec/containers/\u003cN\u003e/image\nIn addition, all images will be processed if the resource object has more than one containers.\n\nIf not nil, only images matches the filters will be processed.",
|
"description": "Predicate filters images before applying the rule.\n\nDefaults to nil, in that case, the system will automatically detect image fields if the resource type is Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet or Job by following rule:\n - Pod: spec/containers/\u003cN\u003e/image\n - ReplicaSet: spec/template/spec/containers/\u003cN\u003e/image\n - Deployment: spec/template/spec/containers/\u003cN\u003e/image\n - DaemonSet: spec/template/spec/containers/\u003cN\u003e/image\n - StatefulSet: spec/template/spec/containers/\u003cN\u003e/image\n - Job: spec/template/spec/containers/\u003cN\u003e/image\nIn addition, all images will be processed if the resource object has more than one container.\n\nIf not nil, only images matches the filters will be processed.",
|
||||||
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.ImagePredicate"
|
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.ImagePredicate"
|
||||||
},
|
},
|
||||||
"value": {
|
"value": {
|
||||||
|
|
|
||||||
|
|
@ -174,15 +174,16 @@ spec:
|
||||||
description: "Predicate filters images before applying
|
description: "Predicate filters images before applying
|
||||||
the rule. \n Defaults to nil, in that case, the
|
the rule. \n Defaults to nil, in that case, the
|
||||||
system will automatically detect image fields if
|
system will automatically detect image fields if
|
||||||
the resource type is Pod, ReplicaSet, Deployment
|
the resource type is Pod, ReplicaSet, Deployment,
|
||||||
or StatefulSet by following rule: - Pod: spec/containers/<N>/image
|
StatefulSet, DaemonSet or Job by following rule:
|
||||||
- ReplicaSet: spec/template/spec/containers/<N>/image
|
- Pod: spec/containers/<N>/image - ReplicaSet: spec/template/spec/containers/<N>/image
|
||||||
- Deployment: spec/template/spec/containers/<N>/image
|
- Deployment: spec/template/spec/containers/<N>/image
|
||||||
|
- DaemonSet: spec/template/spec/containers/<N>/image
|
||||||
- StatefulSet: spec/template/spec/containers/<N>/image
|
- StatefulSet: spec/template/spec/containers/<N>/image
|
||||||
In addition, all images will be processed if the
|
- Job: spec/template/spec/containers/<N>/image In
|
||||||
resource object has more than one containers. \n
|
addition, all images will be processed if the resource
|
||||||
If not nil, only images matches the filters will
|
object has more than one container. \n If not nil,
|
||||||
be processed."
|
only images matches the filters will be processed."
|
||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
description: Path indicates the path of target
|
description: Path indicates the path of target
|
||||||
|
|
@ -495,13 +496,16 @@ spec:
|
||||||
description: "Predicate filters images before applying the
|
description: "Predicate filters images before applying the
|
||||||
rule. \n Defaults to nil, in that case, the system will
|
rule. \n Defaults to nil, in that case, the system will
|
||||||
automatically detect image fields if the resource type
|
automatically detect image fields if the resource type
|
||||||
is Pod, ReplicaSet, Deployment or StatefulSet by following
|
is Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet
|
||||||
rule: - Pod: spec/containers/<N>/image - ReplicaSet: spec/template/spec/containers/<N>/image
|
or Job by following rule: - Pod: spec/containers/<N>/image
|
||||||
|
- ReplicaSet: spec/template/spec/containers/<N>/image
|
||||||
- Deployment: spec/template/spec/containers/<N>/image
|
- Deployment: spec/template/spec/containers/<N>/image
|
||||||
- StatefulSet: spec/template/spec/containers/<N>/image
|
- DaemonSet: spec/template/spec/containers/<N>/image -
|
||||||
In addition, all images will be processed if the resource
|
StatefulSet: spec/template/spec/containers/<N>/image -
|
||||||
object has more than one containers. \n If not nil, only
|
Job: spec/template/spec/containers/<N>/image In addition,
|
||||||
images matches the filters will be processed."
|
all images will be processed if the resource object has
|
||||||
|
more than one container. \n If not nil, only images matches
|
||||||
|
the filters will be processed."
|
||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
description: Path indicates the path of target field
|
description: Path indicates the path of target field
|
||||||
|
|
|
||||||
|
|
@ -174,15 +174,16 @@ spec:
|
||||||
description: "Predicate filters images before applying
|
description: "Predicate filters images before applying
|
||||||
the rule. \n Defaults to nil, in that case, the
|
the rule. \n Defaults to nil, in that case, the
|
||||||
system will automatically detect image fields if
|
system will automatically detect image fields if
|
||||||
the resource type is Pod, ReplicaSet, Deployment
|
the resource type is Pod, ReplicaSet, Deployment,
|
||||||
or StatefulSet by following rule: - Pod: spec/containers/<N>/image
|
StatefulSet, DaemonSet or Job by following rule:
|
||||||
- ReplicaSet: spec/template/spec/containers/<N>/image
|
- Pod: spec/containers/<N>/image - ReplicaSet: spec/template/spec/containers/<N>/image
|
||||||
- Deployment: spec/template/spec/containers/<N>/image
|
- Deployment: spec/template/spec/containers/<N>/image
|
||||||
|
- DaemonSet: spec/template/spec/containers/<N>/image
|
||||||
- StatefulSet: spec/template/spec/containers/<N>/image
|
- StatefulSet: spec/template/spec/containers/<N>/image
|
||||||
In addition, all images will be processed if the
|
- Job: spec/template/spec/containers/<N>/image In
|
||||||
resource object has more than one containers. \n
|
addition, all images will be processed if the resource
|
||||||
If not nil, only images matches the filters will
|
object has more than one container. \n If not nil,
|
||||||
be processed."
|
only images matches the filters will be processed."
|
||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
description: Path indicates the path of target
|
description: Path indicates the path of target
|
||||||
|
|
@ -495,13 +496,16 @@ spec:
|
||||||
description: "Predicate filters images before applying the
|
description: "Predicate filters images before applying the
|
||||||
rule. \n Defaults to nil, in that case, the system will
|
rule. \n Defaults to nil, in that case, the system will
|
||||||
automatically detect image fields if the resource type
|
automatically detect image fields if the resource type
|
||||||
is Pod, ReplicaSet, Deployment or StatefulSet by following
|
is Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet
|
||||||
rule: - Pod: spec/containers/<N>/image - ReplicaSet: spec/template/spec/containers/<N>/image
|
or Job by following rule: - Pod: spec/containers/<N>/image
|
||||||
|
- ReplicaSet: spec/template/spec/containers/<N>/image
|
||||||
- Deployment: spec/template/spec/containers/<N>/image
|
- Deployment: spec/template/spec/containers/<N>/image
|
||||||
- StatefulSet: spec/template/spec/containers/<N>/image
|
- DaemonSet: spec/template/spec/containers/<N>/image -
|
||||||
In addition, all images will be processed if the resource
|
StatefulSet: spec/template/spec/containers/<N>/image -
|
||||||
object has more than one containers. \n If not nil, only
|
Job: spec/template/spec/containers/<N>/image In addition,
|
||||||
images matches the filters will be processed."
|
all images will be processed if the resource object has
|
||||||
|
more than one container. \n If not nil, only images matches
|
||||||
|
the filters will be processed."
|
||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
description: Path indicates the path of target field
|
description: Path indicates the path of target field
|
||||||
|
|
|
||||||
|
|
@ -132,12 +132,14 @@ type ImageOverrider struct {
|
||||||
// Predicate filters images before applying the rule.
|
// Predicate filters images before applying the rule.
|
||||||
//
|
//
|
||||||
// Defaults to nil, in that case, the system will automatically detect image fields if the resource type is
|
// Defaults to nil, in that case, the system will automatically detect image fields if the resource type is
|
||||||
// Pod, ReplicaSet, Deployment or StatefulSet by following rule:
|
// Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet or Job by following rule:
|
||||||
// - Pod: spec/containers/<N>/image
|
// - Pod: spec/containers/<N>/image
|
||||||
// - ReplicaSet: spec/template/spec/containers/<N>/image
|
// - ReplicaSet: spec/template/spec/containers/<N>/image
|
||||||
// - Deployment: spec/template/spec/containers/<N>/image
|
// - Deployment: spec/template/spec/containers/<N>/image
|
||||||
|
// - DaemonSet: spec/template/spec/containers/<N>/image
|
||||||
// - StatefulSet: spec/template/spec/containers/<N>/image
|
// - StatefulSet: spec/template/spec/containers/<N>/image
|
||||||
// In addition, all images will be processed if the resource object has more than one containers.
|
// - Job: spec/template/spec/containers/<N>/image
|
||||||
|
// In addition, all images will be processed if the resource object has more than one container.
|
||||||
//
|
//
|
||||||
// If not nil, only images matches the filters will be processed.
|
// If not nil, only images matches the filters will be processed.
|
||||||
// +optional
|
// +optional
|
||||||
|
|
|
||||||
|
|
@ -2754,7 +2754,7 @@ func schema_pkg_apis_policy_v1alpha1_ImageOverrider(ref common.ReferenceCallback
|
||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"predicate": {
|
"predicate": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Description: "Predicate filters images before applying the rule.\n\nDefaults to nil, in that case, the system will automatically detect image fields if the resource type is Pod, ReplicaSet, Deployment or StatefulSet by following rule:\n - Pod: spec/containers/<N>/image\n - ReplicaSet: spec/template/spec/containers/<N>/image\n - Deployment: spec/template/spec/containers/<N>/image\n - StatefulSet: spec/template/spec/containers/<N>/image\nIn addition, all images will be processed if the resource object has more than one containers.\n\nIf not nil, only images matches the filters will be processed.",
|
Description: "Predicate filters images before applying the rule.\n\nDefaults to nil, in that case, the system will automatically detect image fields if the resource type is Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet or Job by following rule:\n - Pod: spec/containers/<N>/image\n - ReplicaSet: spec/template/spec/containers/<N>/image\n - Deployment: spec/template/spec/containers/<N>/image\n - DaemonSet: spec/template/spec/containers/<N>/image\n - StatefulSet: spec/template/spec/containers/<N>/image\n - Job: spec/template/spec/containers/<N>/image\nIn addition, all images will be processed if the resource object has more than one container.\n\nIf not nil, only images matches the filters will be processed.",
|
||||||
Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.ImagePredicate"),
|
Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.ImagePredicate"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,25 @@ func generateDeploymentYamlWithTwoContainer() *unstructured.Unstructured {
|
||||||
}}}}}}}
|
}}}}}}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateJobYaml() *unstructured.Unstructured {
|
||||||
|
return &unstructured.Unstructured{
|
||||||
|
Object: map[string]interface{}{
|
||||||
|
"apiVersion": "batch/v1",
|
||||||
|
"kind": "Job",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "pi",
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"template": map[string]interface{}{
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"containers": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"image": "perl:5.34.0",
|
||||||
|
"name": "perl",
|
||||||
|
},
|
||||||
|
}}}}}}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseJSONPatchesByImageOverrider(t *testing.T) {
|
func TestParseJSONPatchesByImageOverrider(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
rawObj *unstructured.Unstructured
|
rawObj *unstructured.Unstructured
|
||||||
|
|
@ -199,6 +218,47 @@ func TestParseJSONPatchesByImageOverrider(t *testing.T) {
|
||||||
want []overrideOption
|
want []overrideOption
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "imageOverrider with empty predicate, resource kind: Job, component: Registry, operator: add",
|
||||||
|
args: args{
|
||||||
|
rawObj: generateJobYaml(),
|
||||||
|
imageOverrider: &policyv1alpha1.ImageOverrider{
|
||||||
|
Component: "Registry",
|
||||||
|
Operator: "add",
|
||||||
|
Value: "k8s.gcr.io",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []overrideOption{
|
||||||
|
{
|
||||||
|
Op: "replace",
|
||||||
|
Path: "/spec/template/spec/containers/0/image",
|
||||||
|
Value: "k8s.gcr.io/perl:5.34.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "imageOverrider with predicate, resource kind: Job, component: Registry, operator: add",
|
||||||
|
args: args{
|
||||||
|
rawObj: generateJobYaml(),
|
||||||
|
imageOverrider: &policyv1alpha1.ImageOverrider{
|
||||||
|
Predicate: &policyv1alpha1.ImagePredicate{
|
||||||
|
Path: "/spec/template/spec/containers/0/image",
|
||||||
|
},
|
||||||
|
Component: "Registry",
|
||||||
|
Operator: "add",
|
||||||
|
Value: "k8s.gcr.io",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []overrideOption{
|
||||||
|
{
|
||||||
|
Op: "replace",
|
||||||
|
Path: "/spec/template/spec/containers/0/image",
|
||||||
|
Value: "k8s.gcr.io/perl:5.34.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "imageOverrider with empty predicate, resource kind: Deployment, component: Registry, operator: add",
|
name: "imageOverrider with empty predicate, resource kind: Deployment, component: Registry, operator: add",
|
||||||
args: args{
|
args: args{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue