Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove CompartmentId mandatory from ocicluster_types #67

Merged
merged 1 commit into from
Apr 23, 2022
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
3 changes: 2 additions & 1 deletion api/v1beta1/ocicluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ type OCIClusterSpec struct {
DefinedTags map[string]map[string]string `json:"definedTags,omitempty"`

// Compartment to create the cluster network.
CompartmentId string `mandatory:"true" json:"compartmentId"`
// +optional
CompartmentId string `json:"compartmentId"`

// Region the cluster operates in. It must be one of available regions in Region Identifier format.
// See https://docs.oracle.com/en-us/iaas/Content/General/Concepts/regions.htm
Expand Down
11 changes: 9 additions & 2 deletions api/v1beta1/ocicluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) error {
func (c *OCICluster) validate() field.ErrorList {
var allErrs field.ErrorList

// simple validity test for compartment
if !validOcid(c.Spec.CompartmentId) {
if len(c.Spec.CompartmentId) <= 0 {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "compartmentId"), c.Spec.CompartmentId, "field is required"))
}

// Handle case where CompartmentId exists, but isn't valid
// the separate "blank" check above is a more clear error for the user
if len(c.Spec.CompartmentId) > 0 && !validOcid(c.Spec.CompartmentId) {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "compartmentId"), c.Spec.CompartmentId, "field is invalid"))
Expand Down
10 changes: 9 additions & 1 deletion api/v1beta1/ocicluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestOCICluster_ValidateCreate(t *testing.T) {
expectErr bool
}{
{
name: "shouldn't allow bad ImageId",
name: "shouldn't allow bad CompartmentId",
c: &OCICluster{
ObjectMeta: metav1.ObjectMeta{},
Spec: OCIClusterSpec{
Expand All @@ -43,6 +43,14 @@ func TestOCICluster_ValidateCreate(t *testing.T) {
},
expectErr: true,
},
{
name: "shouldn't allow blank CompartmentId",
c: &OCICluster{
ObjectMeta: metav1.ObjectMeta{},
Spec: OCIClusterSpec{},
},
expectErr: true,
},
{
name: "should succeed",
c: &OCICluster{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,6 @@ spec:
description: Region the cluster operates in. It must be one of available
regions in Region Identifier format. See https://docs.oracle.com/en-us/iaas/Content/General/Concepts/regions.htm
type: string
required:
- compartmentId
type: object
status:
description: OCIClusterStatus defines the observed state of OCICluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,6 @@ spec:
description: Region the cluster operates in. It must be one
of available regions in Region Identifier format. See https://docs.oracle.com/en-us/iaas/Content/General/Concepts/regions.htm
type: string
required:
- compartmentId
type: object
required:
- spec
Expand Down
5 changes: 2 additions & 3 deletions templates/clusterclass-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
matchResources:
infrastructureCluster: true
jsonPatches:
- op: replace
- op: add
path: "/spec/template/spec/compartmentId"
valueFrom:
variable: compartmentId
Expand Down Expand Up @@ -162,8 +162,7 @@ metadata:
name: ocicluster
spec:
template:
spec:
compartmentId: REPLACE
spec: {}
---
kind: KubeadmControlPlaneTemplate
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
matchResources:
infrastructureCluster: true
jsonPatches:
- op: replace
- op: add
path: "/spec/template/spec/compartmentId"
valueFrom:
variable: compartmentId
Expand Down Expand Up @@ -162,8 +162,7 @@ metadata:
name: ocicluster
spec:
template:
spec:
compartmentId: REPLACE
spec: {}
---
kind: KubeadmControlPlaneTemplate
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
Expand Down