Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -24,7 +24,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -40,7 +40,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -55,7 +55,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -71,7 +71,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -88,7 +88,7 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
Expand All @@ -101,12 +101,184 @@ tests:
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: foobar
name: worker
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
- name: Should succeed when MachineOSConfig name matches MachineConfigPool name
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: worker
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: worker
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
- name: Should fail when MachineOSConfig name does not match MachineConfigPool name
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
expectedError: "MachineOSConfig name must match the referenced MachineConfigPool name; can only have one MachineOSConfig per MachineConfigPool"
onUpdate:
- name: Should allow changing other fields when a persisted value is no longer valid (mismatched names)
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/x-kubernetes-validations # Remove the name matching validation
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:v2.0
containerFile:
- containerfileArch: AMD64
content: |
FROM configs AS final
RUN rpm-ostree install tree && \
ostree container commit
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:v2.0
containerFile:
- containerfileArch: AMD64
content: |
FROM configs AS final
RUN rpm-ostree install tree && \
ostree container commit
- name: Should allow updating a persisted value that is no longer valid to a valid value (fix mismatched names)
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/x-kubernetes-validations # Remove the name matching validation
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: worker
spec:
machineConfigPool:
name: different-pool
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: worker
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: worker
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
- name: Should not allow updating a persisted value that is no longer valid to a still invalid value (different mismatched MCP names)
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/x-kubernetes-validations # Remove the name matching validation
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineOSConfig
metadata:
name: different-name
spec:
machineConfigPool:
name: worker-different
imageBuilder:
imageBuilderType: Job
renderedImagePushSecret:
name: foo
renderedImagePushSpec: quay.io/mco/renderedImg:latest
expectedError: "MachineOSConfig name must match the referenced MachineConfigPool name; can only have one MachineOSConfig per MachineConfigPool"
1 change: 1 addition & 0 deletions machineconfiguration/v1/types_machineosconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// MachineOSConfig describes the configuration for a build process managed by the MCO
// Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer).
// +openshift:compatibility-gen:level=1
// +kubebuilder:validation:XValidation:rule="self.metadata.name == self.spec.machineConfigPool.name || oldSelf.hasValue() && oldSelf.spec.machineConfigPool.name.value() == self.spec.machineConfigPool.name",optionalOldSelf=true,message="MachineOSConfig name must match the referenced MachineConfigPool name; can only have one MachineOSConfig per MachineConfigPool"
type MachineOSConfig struct {
metav1.TypeMeta `json:",inline"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: MachineOSConfig name must match the referenced MachineConfigPool
name; can only have one MachineOSConfig per MachineConfigPool
optionalOldSelf: true
rule: self.metadata.name == self.spec.machineConfigPool.name || oldSelf.hasValue()
&& oldSelf.spec.machineConfigPool.name.value() == self.spec.machineConfigPool.name
served: true
storage: true
subresources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: MachineOSConfig name must match the referenced MachineConfigPool
name; can only have one MachineOSConfig per MachineConfigPool
optionalOldSelf: true
rule: self.metadata.name == self.spec.machineConfigPool.name || oldSelf.hasValue()
&& oldSelf.spec.machineConfigPool.name.value() == self.spec.machineConfigPool.name
served: true
storage: true
subresources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: MachineOSConfig name must match the referenced MachineConfigPool
name; can only have one MachineOSConfig per MachineConfigPool
optionalOldSelf: true
rule: self.metadata.name == self.spec.machineConfigPool.name || oldSelf.hasValue()
&& oldSelf.spec.machineConfigPool.name.value() == self.spec.machineConfigPool.name
served: true
storage: true
subresources:
Expand Down