Skip to content

Commit 841a76f

Browse files
Add nodeDrainTimeout to e2e tests
Signed-off-by: killianmuldoon <[email protected]>
1 parent 5d92925 commit 841a76f

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

internal/contract/controlplane_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestControlPlane(t *testing.T) {
153153
g := NewWithT(t)
154154

155155
duration := metav1.Duration{Duration: 2*time.Minute + 5*time.Second}
156-
156+
expectedDurationString := "2m5s"
157157
g.Expect(ControlPlane().MachineTemplate().NodeDrainTimeout().Path()).To(Equal(Path{"spec", "machineTemplate", "nodeDrainTimeout"}))
158158

159159
err := ControlPlane().MachineTemplate().NodeDrainTimeout().Set(obj, duration)
@@ -163,6 +163,12 @@ func TestControlPlane(t *testing.T) {
163163
g.Expect(err).ToNot(HaveOccurred())
164164
g.Expect(got).ToNot(BeNil())
165165
g.Expect(*got).To(Equal(duration))
166+
167+
// Check that the literal string value of the duration is correctly formatted.
168+
durationString, found, err := unstructured.NestedString(obj.UnstructuredContent(), "spec", "machineTemplate", "nodeDrainTimeout")
169+
g.Expect(err).ToNot(HaveOccurred())
170+
g.Expect(found).To(BeTrue())
171+
g.Expect(durationString).To(Equal(expectedDurationString))
166172
})
167173
}
168174

internal/contract/types.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package contract
1818

1919
import (
20+
"strconv"
2021
"strings"
2122

2223
"github.com/pkg/errors"
@@ -151,7 +152,7 @@ func (i *Duration) Get(obj *unstructured.Unstructured) (*metav1.Duration, error)
151152
}
152153

153154
d := &metav1.Duration{}
154-
if err := d.UnmarshalJSON([]byte(durationString)); err != nil {
155+
if err := d.UnmarshalJSON([]byte(strconv.Quote(durationString))); err != nil {
155156
return nil, errors.Wrapf(err, "failed to unmarshal duration %s from object", "."+strings.Join(i.path, "."))
156157
}
157158

@@ -160,12 +161,7 @@ func (i *Duration) Get(obj *unstructured.Unstructured) (*metav1.Duration, error)
160161

161162
// Set sets the metav1.Duration value in the path.
162163
func (i *Duration) Set(obj *unstructured.Unstructured, value metav1.Duration) error {
163-
durationString, err := value.MarshalJSON()
164-
if err != nil {
165-
return errors.Wrapf(err, "failed to marshal duration %s", value.Duration.String())
166-
}
167-
168-
if err := unstructured.SetNestedField(obj.UnstructuredContent(), string(durationString), i.path...); err != nil {
164+
if err := unstructured.SetNestedField(obj.UnstructuredContent(), value.Duration.String(), i.path...); err != nil {
169165
return errors.Wrapf(err, "failed to set path %s of object %v", "."+strings.Join(i.path, "."), obj.GroupVersionKind())
170166
}
171167
return nil

internal/controllers/topology/cluster/desired_state_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20-
"fmt"
2120
"strings"
2221
"testing"
2322
"time"
@@ -315,7 +314,7 @@ func TestComputeControlPlane(t *testing.T) {
315314

316315
assertNestedField(g, obj, version, contract.ControlPlane().Version().Path()...)
317316
assertNestedField(g, obj, int64(replicas), contract.ControlPlane().Replicas().Path()...)
318-
assertNestedField(g, obj, fmt.Sprintf("%q", duration), contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path()...)
317+
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path()...)
319318
assertNestedFieldUnset(g, obj, contract.ControlPlane().MachineTemplate().InfrastructureRef().Path()...)
320319

321320
// Ensure no ownership is added to generated ControlPlane.

test/e2e/data/infrastructure-docker/v1beta1/bases/cluster-with-topology.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ spec:
1717
version: "${KUBERNETES_VERSION}"
1818
controlPlane:
1919
metadata: {}
20+
nodeDrainTimeout: "30s"
2021
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
2122
workers:
2223
machineDeployments:
2324
- class: "default-worker"
2425
name: "md-0"
26+
nodeDrainTimeout: "30s"
2527
replicas: ${WORKER_MACHINE_COUNT}
2628
failureDomain: fd4
2729
variables:

0 commit comments

Comments
 (0)