Skip to content

Commit eb289e8

Browse files
committed
Fix e2e tests
1 parent e35938f commit eb289e8

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

internal/controllers/topology/cluster/patches/engine.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package patches
1919

2020
import (
21+
"bytes"
2122
"context"
2223
"fmt"
2324
"runtime/debug"
@@ -464,12 +465,26 @@ func applyPatchToRequest(ctx context.Context, req *runtimehooksv1.GeneratePatche
464465
return errors.Wrap(err, "failed to apply patch: error decoding json patch (RFC6902)")
465466
}
466467

468+
if len(jsonPatch) == 0 {
469+
// Return if there are no patches, nothing to do.
470+
// If the requestItem.Object does not have a spec and we don't have a patch that adds one,
471+
// patchTemplateSpec below would fail, so let's return early.
472+
return nil
473+
}
474+
467475
patchedTemplate, err = jsonPatch.Apply(requestItem.Object.Raw)
468476
if err != nil {
469477
log.Error(err, fmt.Sprintf("Failed to apply patch with uid %q: error applying json patch (RFC6902)", requestItem.UID), "patch", string(patch.Patch))
470478
return errors.Wrap(err, "failed to apply patch: error applying json patch (RFC6902)")
471479
}
472480
case runtimehooksv1.JSONMergePatchType:
481+
if len(patch.Patch) == 0 || bytes.Equal(patch.Patch, []byte("{}")) {
482+
// Return if there are no patches, nothing to do.
483+
// If the requestItem.Object does not have a spec and we don't have a patch that adds one,
484+
// patchTemplateSpec below would fail, so let's return early.
485+
return nil
486+
}
487+
473488
log.V(5).Info("Accumulating JSON merge patch", "patch", string(patch.Patch))
474489
patchedTemplate, err = jsonpatch.MergePatch(requestItem.Object.Raw, patch.Patch)
475490
if err != nil {

internal/controllers/topology/cluster/patches/patch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ func copySpec(in copySpecInput) error {
195195
// Get spec from src.
196196
srcSpec, found, err := unstructured.NestedFieldNoCopy(in.src.Object, strings.Split(in.srcSpecPath, ".")...)
197197
if !found {
198-
return errors.Errorf("missing field %q in %s %s", in.srcSpecPath, in.src.GetKind(), klog.KObj(in.src))
198+
// Return if srcSpecPath does not exist in src, nothing to do.
199+
return nil
199200
} else if err != nil {
200201
return errors.Wrapf(err, "failed to get field %q from %s %s", in.srcSpecPath, in.src.GetKind(), klog.KObj(in.src))
201202
}

test/e2e/data/infrastructure-docker/main/bases/md.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
1919
kind: KubeadmConfigTemplate
2020
metadata:
2121
name: "${CLUSTER_NAME}-md-0"
22-
spec:
23-
template:
24-
spec:
25-
joinConfiguration:
2622
---
2723
# MachineDeployment object
2824
apiVersion: cluster.x-k8s.io/v1beta2

test/e2e/data/infrastructure-docker/main/bases/mp.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,3 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
4242
kind: KubeadmConfig
4343
metadata:
4444
name: "${CLUSTER_NAME}-mp-0-config"
45-
spec:
46-
joinConfiguration:

test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,3 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
139139
kind: KubeadmConfigTemplate
140140
metadata:
141141
name: quick-start-default-worker-bootstraptemplate
142-
spec:
143-
template:
144-
spec:
145-
joinConfiguration:

0 commit comments

Comments
 (0)