-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add Zones field to InstanceGroup #3439
Add Zones field to InstanceGroup #3439
Conversation
@justinsb PR needs rebase |
92b3f54
to
8eba0f1
Compare
allZones.Insert(c.Zones...) | ||
allZones.Insert(c.MasterZones...) | ||
|
||
if cluster.Spec.CloudProvider == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just moved up from lower...
} | ||
} | ||
|
||
if len(cluster.Spec.Subnets) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is covered by the explicit Zones check above
|
||
if c.MasterCount != 0 && c.MasterCount < int32(len(masterSubnets)) { | ||
return fmt.Errorf("specified %d master zones, but also requested %d masters. If specifying both, the count should match.", len(masterSubnets), c.MasterCount) | ||
masterZones := c.MasterZones |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic is clearer and fixes the bug when you specify zones and master-count
g.ObjectMeta.Name = "nodes" | ||
|
||
subnetNames := sets.NewString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We explicitly initialize subnets/zones - it is safer, and we don't necessarily have all the information later in the GCE case
@@ -235,15 +235,25 @@ func Convert_kops_EtcdMemberSpec_To_v1alpha1_EtcdMemberSpec(in *kops.EtcdMemberS | |||
} | |||
|
|||
func Convert_v1alpha1_InstanceGroupSpec_To_kops_InstanceGroupSpec(in *InstanceGroupSpec, out *kops.InstanceGroupSpec, s conversion.Scope) error { | |||
err := autoConvert_v1alpha1_InstanceGroupSpec_To_kops_InstanceGroupSpec(in, out, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed order here to preserve the logic, now that the autogenerated code has Zones fields...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this impact auto-generated code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not.
pkg/apis/kops/validation/legacy.go
Outdated
switch kops.CloudProviderID(c.Spec.CloudProvider) { | ||
case kops.CloudProviderBareMetal: | ||
requiresSubnets = false | ||
requiresNetworkCIDR = false | ||
if c.Spec.NetworkCIDR != "" { | ||
return field.Invalid(fieldSpec.Child("NetworkCIDR"), c.Spec.NetworkCIDR, "NetworkCIDR should not be set on bare metal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the NetworkCIDR is ignored, makes more sense to error if it is set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to another PR? I love it, but it kinda does not apply to the work you are doing.
@@ -43,29 +43,31 @@ func PerformAssignments(c *kops.Cluster) error { | |||
return err | |||
} | |||
|
|||
if c.SharedVPC() && c.Spec.NetworkCIDR == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same code just refactored, and only done for AWS now
@@ -69,3 +70,13 @@ func LastComponent(s string) string { | |||
} | |||
return s | |||
} | |||
|
|||
// ZoneToRegion maps a GCE zone name to a GCE region name, returning an error if it cannot be mapped | |||
func ZoneToRegion(zone string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled this into a helper function
@@ -40,20 +40,13 @@ func BuildCloud(cluster *kops.Cluster) (fi.Cloud, error) { | |||
switch kops.CloudProviderID(cluster.Spec.CloudProvider) { | |||
case kops.CloudProviderGCE: | |||
{ | |||
nodeZones := make(map[string]bool) | |||
for _, subnet := range cluster.Spec.Subnets { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got much easier :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of questions... You want this in for 1.8?? Refactoring like this kinda makes me nervous before a release :)
if len(c.Zones) == 0 { | ||
return fmt.Errorf("must specify at least one zone for the cluster (use --zones)") | ||
} else if api.CloudProviderID(cluster.Spec.CloudProvider) == api.CloudProviderGCE { | ||
// On GCE, subnets are regional - we create one per region, not per zone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this code in the cloud provider rather than create? Move it into an interfaced method as all cloud providers would have to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can see how this goes I suspect as we add more clouds
@@ -324,8 +325,10 @@ type ClusterSubnetSpec struct { | |||
Name string `json:"name,omitempty"` | |||
// CIDR is the network cidr of the subnet | |||
CIDR string `json:"cidr,omitempty"` | |||
// Zone is the zone the subnet resides | |||
// Zone is the zone the subnet is in, set for subnets that are zonally scoped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just have one value to use across all providers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand
@@ -235,15 +235,25 @@ func Convert_kops_EtcdMemberSpec_To_v1alpha1_EtcdMemberSpec(in *kops.EtcdMemberS | |||
} | |||
|
|||
func Convert_v1alpha1_InstanceGroupSpec_To_kops_InstanceGroupSpec(in *InstanceGroupSpec, out *kops.InstanceGroupSpec, s conversion.Scope) error { | |||
err := autoConvert_v1alpha1_InstanceGroupSpec_To_kops_InstanceGroupSpec(in, out, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this impact auto-generated code?
pkg/apis/kops/validation/legacy.go
Outdated
switch kops.CloudProviderID(c.Spec.CloudProvider) { | ||
case kops.CloudProviderBareMetal: | ||
requiresSubnets = false | ||
requiresNetworkCIDR = false | ||
if c.Spec.NetworkCIDR != "" { | ||
return field.Invalid(fieldSpec.Child("NetworkCIDR"), c.Spec.NetworkCIDR, "NetworkCIDR should not be set on bare metal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to another PR? I love it, but it kinda does not apply to the work you are doing.
return field.Invalid(fieldSpec.Child("NetworkCIDR"), c.Spec.NetworkCIDR, "NetworkCIDR should not be set on bare metal") | ||
} | ||
|
||
case kops.CloudProviderGCE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above. Can we break this into a different PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will move the bare metal one into another PR, but it's not really practical to split out the GCE logic here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #3495
@justinsb PR needs rebase |
8eba0f1
to
2658cc7
Compare
/lgtm |
2658cc7
to
4ab27fb
Compare
/lgtm cancel //PR changed after LGTM, removing LGTM. @chrislovecnm @justinsb |
/lgtm |
@justinsb PR needs rebase |
4ab27fb
to
67e3dea
Compare
Trivial rebase (imports), will reapply LGTM |
/lgtm cancel //PR changed after LGTM, removing LGTM. @chrislovecnm @justinsb |
/test all [submit-queue is verifying that this PR is safe to merge] |
We also make the subnet zone and CIDR optional on GCE
The Zones field can specify zones where they are not specified on a Subnet, for example on GCE where we have regional subnets.
67e3dea
to
7fd1196
Compare
/lgtm cancel //PR changed after LGTM, removing LGTM. @chrislovecnm @justinsb |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chrislovecnm The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. |
The Zones field can specify zones where they are not specified on a
Subnet, for example on GCE where we have regional subnets.