Skip to content

Fix MachineSet replicas type: int32 instead of string#12

Merged
wkulhanek merged 1 commit into
mainfrom
fix/machineset-replicas-type
Apr 20, 2026
Merged

Fix MachineSet replicas type: int32 instead of string#12
wkulhanek merged 1 commit into
mainfrom
fix/machineset-replicas-type

Conversation

@rut31337
Copy link
Copy Markdown
Contributor

Summary

  • Remove quotes from replicas: "{{ item.1 | int }}" in create_new_machinesets.yml
  • The quoted Jinja expression renders as a YAML string in the k8s module's definition block, causing the OCP admission webhook to reject it

Problem

When creating new MachineSets with a different instance type, the replicas field is serialized as a string ("2") instead of an integer (2). The admission webhook rejects this:

admission webhook "default.machineset.machine.openshift.io" denied the request:
json: cannot unmarshal string into Go struct field MachineSetSpec.spec.replicas of type int32

Observed on: summit-2026.lb1216-demystifying-aap-on-ocp-cluster.dev (AWS, m6a.12xlarge workers)

Test plan

  • Verify MachineSet creation succeeds with the unquoted expression
  • Confirm worker nodes come up with the correct instance type and count

wkulhanek
wkulhanek previously approved these changes Apr 20, 2026
…lization

The admission webhook rejects MachineSet creation with:
  json: cannot unmarshal string into Go struct field
  MachineSetSpec.spec.replicas of type int32

The quoted Jinja expression "{{ item.1 | int }}" renders as a YAML
string in the k8s module's definition block. Removing quotes lets
Ansible's native type handling pass it as an integer.
@rut31337 rut31337 force-pushed the fix/machineset-replicas-type branch from 56eab93 to c056292 Compare April 20, 2026 12:02
@rut31337
Copy link
Copy Markdown
Contributor Author

Updated the approach — simply removing quotes from the Jinja expression breaks YAML parsing (bare {{ }} is interpreted as a flow mapping).

The fix uses to_json | from_json round-trip on the definition variable. This converts the Jinja-rendered string "2" back to native integer 2 through JSON parsing, while keeping the YAML valid:

definition: >-
  {{ _machineset_def | to_json | from_json }}
vars:
  _machineset_def:
    spec:
      replicas: "{{ item.1 | int }}"

yamllint and ansible-lint (production profile) both pass locally.

@wkulhanek wkulhanek merged commit 065b695 into main Apr 20, 2026
1 check passed
@wkulhanek wkulhanek deleted the fix/machineset-replicas-type branch April 20, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants