@@ -147,8 +147,13 @@ func validateClusterTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, cl
147147
148148// validate server pools
149149func (c * Cluster ) validateInstancePools () (result error ) {
150- return nil
151- //return fmt.Errorf("refactore me!")
150+ for _ , instancePool := range c .InstancePools () {
151+ err := instancePool .Validate ()
152+ if err != nil {
153+ result = multierror .Append (result , err )
154+ }
155+ }
156+ return result
152157}
153158
154159// Verify cluster
@@ -189,6 +194,15 @@ func (c *Cluster) Validate() (result error) {
189194 result = multierror .Append (result , err )
190195 }
191196
197+ //validate apiserver
198+ if k := c .Config ().Kubernetes ; k != nil {
199+ if apiServer := k .APIServer ; apiServer != nil {
200+ if err := c .validateAPIServer (); err != nil {
201+ result = multierror .Append (result , err )
202+ }
203+ }
204+ }
205+
192206 return result
193207}
194208
@@ -235,6 +249,18 @@ func (c *Cluster) validateLoggingSinks() (result error) {
235249 return nil
236250}
237251
252+ // Validate APIServer
253+ func (c * Cluster ) validateAPIServer () (result error ) {
254+ for _ , cidr := range c .Config ().Kubernetes .APIServer .AllowCIDRs {
255+ _ , _ , err := net .ParseCIDR (cidr )
256+ if err != nil {
257+ result = multierror .Append (result , fmt .Errorf ("%s is not a valid CIDR format" , cidr ))
258+ }
259+ }
260+
261+ return result
262+ }
263+
238264// Determine if this Cluster is a cluster or hub, single or multi environment
239265func (c * Cluster ) Type () string {
240266 if c .conf .Type != "" {
@@ -392,6 +418,11 @@ func (c *Cluster) Variables() map[string]interface{} {
392418 if ok {
393419 output [fmt .Sprintf ("%s_ami" , instancePool .TFName ())] = ids
394420 }
421+ if instancePool .Config ().AllowCIDRs != nil {
422+ output [fmt .Sprintf ("%s_admin_cidrs" , instancePool .TFName ())] = instancePool .Config ().AllowCIDRs
423+ } else {
424+ output [fmt .Sprintf ("%s_admin_cidrs" , instancePool .TFName ())] = c .environment .Config ().AdminCIDRs
425+ }
395426 output [fmt .Sprintf ("%s_min_instance_count" , instancePool .TFName ())] = instancePool .Config ().MinCount
396427 output [fmt .Sprintf ("%s_max_instance_count" , instancePool .TFName ())] = instancePool .Config ().MaxCount
397428 }
@@ -426,6 +457,17 @@ func (c *Cluster) Variables() map[string]interface{} {
426457 }
427458 }
428459
460+ // Get Apiserver valid admin cidrs
461+ if k := c .Config ().Kubernetes ; k != nil {
462+ if apiServer := k .APIServer ; apiServer != nil && apiServer .AllowCIDRs != nil {
463+ output ["api_admin_cidrs" ] = apiServer .AllowCIDRs
464+ } else {
465+ output ["api_admin_cidrs" ] = c .environment .Config ().AdminCIDRs
466+ }
467+ } else {
468+ output ["api_admin_cidrs" ] = c .environment .Config ().AdminCIDRs
469+ }
470+
429471 // publish changed private zone
430472 if privateZone := c .Environment ().Config ().PrivateZone ; privateZone != "" {
431473 output ["private_zone" ] = privateZone
0 commit comments