Skip to content

Commit

Permalink
Merge pull request #537 from jichenjc/bug/530
Browse files Browse the repository at this point in the history
Add availability zone to be used by controller plane
  • Loading branch information
k8s-ci-robot committed Apr 3, 2020
2 parents 68df748 + fd58fc0 commit 7c28119
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/v1alpha3/openstackcluster_types.go
Expand Up @@ -115,6 +115,9 @@ type OpenStackClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// ControlPlaneAvailabilityZones is the az to deploy control plane to
ControlPlaneAvailabilityZones []string `json:"controlPlaneAvailabilityZones,omitempty"`
}

// OpenStackClusterStatus defines the observed state of OpenStackCluster
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -101,6 +101,12 @@ spec:
name must be unique.
type: string
type: object
controlPlaneAvailabilityZones:
description: ControlPlaneAvailabilityZones is the az to deploy control
plane to
items:
type: string
type: array
controlPlaneEndpoint:
description: ControlPlaneEndpoint represents the endpoint used to
communicate with the control plane.
Expand Down
23 changes: 22 additions & 1 deletion controllers/openstackcluster_controller.go
Expand Up @@ -177,6 +177,15 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, log lo
return ctrl.Result{}, nil
}

func contains(arr []string, target string) bool {
for _, a := range arr {
if a == target {
return true
}
}
return false
}

func (r *OpenStackClusterReconciler) reconcileNormal(ctx context.Context, log logr.Logger, patchHelper *patch.Helper, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) {
log.Info("Reconciling Cluster")

Expand Down Expand Up @@ -308,8 +317,20 @@ func (r *OpenStackClusterReconciler) reconcileNormal(ctx context.Context, log lo
if az.ZoneName == "internal" {
continue
}

found := true
// If Az given, then check whether it's in the allow list
// If no Az given, then by default put into allow list
if len(openStackCluster.Spec.ControlPlaneAvailabilityZones) > 0 {
if contains(openStackCluster.Spec.ControlPlaneAvailabilityZones, az.ZoneName) {
found = true
} else {
found = false
}
}

openStackCluster.Status.FailureDomains[az.ZoneName] = clusterv1.FailureDomainSpec{
ControlPlane: true,
ControlPlane: found,
}
}

Expand Down

0 comments on commit 7c28119

Please sign in to comment.