Skip to content

Commit

Permalink
Set empty objects instead error on create
Browse files Browse the repository at this point in the history
  • Loading branch information
rawmind0 committed May 6, 2021
1 parent a7625e3 commit 628d3c1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions internal/gke/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,50 +202,51 @@ func validateCreateRequest(ctx context.Context, client *gkeapi.Service, config *
return nil
}

emptyString := ""
if config.Spec.EnableKubernetesAlpha == nil {
return fmt.Errorf(cannotBeNilError, "enableKubernetesAlpha", config.Name)
}
if config.Spec.KubernetesVersion == nil {
return fmt.Errorf(cannotBeNilError, "kubernetesVersion", config.Name)
}
if config.Spec.ClusterIpv4CidrBlock == nil {
return fmt.Errorf(cannotBeNilError, "clusterIpv4CidrBlock", config.Name)
config.Spec.ClusterIpv4CidrBlock = &emptyString
}
if config.Spec.ClusterAddons == nil {
return fmt.Errorf(cannotBeNilError, "clusterAddons", config.Name)
config.Spec.ClusterAddons = &gkev1.GKEClusterAddons{}
}
if config.Spec.IPAllocationPolicy == nil {
return fmt.Errorf(cannotBeNilError, "ipAllocationPolicy", config.Name)
config.Spec.IPAllocationPolicy = &gkev1.GKEIPAllocationPolicy{}
}
if config.Spec.LoggingService == nil {
return fmt.Errorf(cannotBeNilError, "loggingService", config.Name)
config.Spec.LoggingService = &emptyString
}
if config.Spec.Network == nil {
return fmt.Errorf(cannotBeNilError, "network", config.Name)
config.Spec.Network = &emptyString
}
if config.Spec.Subnetwork == nil {
return fmt.Errorf(cannotBeNilError, "subnetwork", config.Name)
config.Spec.Subnetwork = &emptyString
}
if config.Spec.NetworkPolicyEnabled == nil {
return fmt.Errorf(cannotBeNilError, "networkPolicyEnabled", config.Name)
}
if config.Spec.PrivateClusterConfig == nil {
return fmt.Errorf(cannotBeNilError, "privateClusterConfig", config.Name)
config.Spec.PrivateClusterConfig = &gkev1.GKEPrivateClusterConfig{}
}
if config.Spec.MasterAuthorizedNetworksConfig == nil {
return fmt.Errorf(cannotBeNilError, "masterAuthorizedNetworksConfig", config.Name)
config.Spec.MasterAuthorizedNetworksConfig = &gkev1.GKEMasterAuthorizedNetworksConfig{}
}
if config.Spec.MonitoringService == nil {
return fmt.Errorf(cannotBeNilError, "monitoringService", config.Name)
config.Spec.MonitoringService = &emptyString
}
if config.Spec.Locations == nil {
return fmt.Errorf(cannotBeNilError, "locations", config.Name)
config.Spec.Locations = []string{}
}
if config.Spec.MaintenanceWindow == nil {
return fmt.Errorf(cannotBeNilError, "maintenanceWindow", config.Name)
config.Spec.MaintenanceWindow = &emptyString
}
if config.Spec.Labels == nil {
return fmt.Errorf(cannotBeNilError, "labels", config.Name)
config.Spec.Labels = map[string]string{}
}

for _, np := range config.Spec.NodePools {
Expand All @@ -267,7 +268,7 @@ func validateNodePoolCreateRequest(clusterName string, np *gkev1.GKENodePoolConf
return fmt.Errorf(nodePoolErr, "version", *np.Name, clusterName)
}
if np.Autoscaling == nil {
return fmt.Errorf(nodePoolErr, "autoscaling", *np.Name, clusterName)
np.Autoscaling = &gkev1.GKENodePoolAutoscaling{}
}
if np.InitialNodeCount == nil {
return fmt.Errorf(nodePoolErr, "initialNodeCount", *np.Name, clusterName)
Expand All @@ -276,10 +277,10 @@ func validateNodePoolCreateRequest(clusterName string, np *gkev1.GKENodePoolConf
return fmt.Errorf(nodePoolErr, "maxPodsConstraint", *np.Name, clusterName)
}
if np.Config == nil {
return fmt.Errorf(nodePoolErr, "config", *np.Name, clusterName)
np.Config = &gkev1.GKENodeConfig{}
}
if np.Management == nil {
return fmt.Errorf(nodePoolErr, "management", *np.Name, clusterName)
np.Management = &gkev1.GKENodePoolManagement{}
}
return nil
}
Expand Down

0 comments on commit 628d3c1

Please sign in to comment.