-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
OpenStack: allow to specify additional networks and security groups for masters and workers #3291
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -86,35 +86,49 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func generateProvider(clusterID string, platform *openstack.Platform, mpool *openstack.MachinePool, osImage string, az string, role, userDataSecret string, trunk string) *openstackprovider.OpenstackProviderSpec { | ||||||||||||||||||||||||||||||||||||||||||
networks := []openstackprovider.NetworkParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Subnets: []openstackprovider.SubnetParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Filter: openstackprovider.SubnetFilter{ | ||||||||||||||||||||||||||||||||||||||||||
Name: fmt.Sprintf("%s-nodes", clusterID), | ||||||||||||||||||||||||||||||||||||||||||
Tags: fmt.Sprintf("%s=%s", "openshiftClusterID", clusterID), | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+89
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
for _, networkID := range mpool.AdditionalNetworkIDs { | ||||||||||||||||||||||||||||||||||||||||||
networks = append(networks, openstackprovider.NetworkParam{ | ||||||||||||||||||||||||||||||||||||||||||
UUID: networkID, | ||||||||||||||||||||||||||||||||||||||||||
NoAllowedAddressPairs: true, | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
securityGroups := []openstackprovider.SecurityGroupParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Name: fmt.Sprintf("%s-%s", clusterID, role), | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
for _, sg := range mpool.AdditionalSecurityGroupIDs { | ||||||||||||||||||||||||||||||||||||||||||
securityGroups = append(securityGroups, openstackprovider.SecurityGroupParam{ | ||||||||||||||||||||||||||||||||||||||||||
UUID: sg, | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
spec := openstackprovider.OpenstackProviderSpec{ | ||||||||||||||||||||||||||||||||||||||||||
TypeMeta: metav1.TypeMeta{ | ||||||||||||||||||||||||||||||||||||||||||
APIVersion: openstackprovider.SchemeGroupVersion.String(), | ||||||||||||||||||||||||||||||||||||||||||
Kind: "OpenstackProviderSpec", | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
Flavor: mpool.FlavorName, | ||||||||||||||||||||||||||||||||||||||||||
CloudName: CloudName, | ||||||||||||||||||||||||||||||||||||||||||
CloudsSecret: &corev1.SecretReference{Name: cloudsSecret, Namespace: cloudsSecretNamespace}, | ||||||||||||||||||||||||||||||||||||||||||
UserDataSecret: &corev1.SecretReference{Name: userDataSecret}, | ||||||||||||||||||||||||||||||||||||||||||
Networks: []openstackprovider.NetworkParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Subnets: []openstackprovider.SubnetParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Filter: openstackprovider.SubnetFilter{ | ||||||||||||||||||||||||||||||||||||||||||
Name: fmt.Sprintf("%s-nodes", clusterID), | ||||||||||||||||||||||||||||||||||||||||||
Tags: fmt.Sprintf("%s=%s", "openshiftClusterID", clusterID), | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
Flavor: mpool.FlavorName, | ||||||||||||||||||||||||||||||||||||||||||
CloudName: CloudName, | ||||||||||||||||||||||||||||||||||||||||||
CloudsSecret: &corev1.SecretReference{Name: cloudsSecret, Namespace: cloudsSecretNamespace}, | ||||||||||||||||||||||||||||||||||||||||||
UserDataSecret: &corev1.SecretReference{Name: userDataSecret}, | ||||||||||||||||||||||||||||||||||||||||||
Networks: networks, | ||||||||||||||||||||||||||||||||||||||||||
AvailabilityZone: az, | ||||||||||||||||||||||||||||||||||||||||||
SecurityGroups: []openstackprovider.SecurityGroupParam{ | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
Name: fmt.Sprintf("%s-%s", clusterID, role), | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
Trunk: trunkSupportBoolean(trunk), | ||||||||||||||||||||||||||||||||||||||||||
SecurityGroups: securityGroups, | ||||||||||||||||||||||||||||||||||||||||||
Trunk: trunkSupportBoolean(trunk), | ||||||||||||||||||||||||||||||||||||||||||
Tags: []string{ | ||||||||||||||||||||||||||||||||||||||||||
fmt.Sprintf("openshiftClusterID=%s", clusterID), | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package validation | |
import ( | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
guuid "github.com/google/uuid" | ||
"github.com/openshift/installer/pkg/types/openstack" | ||
) | ||
|
||
|
@@ -20,5 +21,35 @@ func ValidateMachinePool(p *openstack.MachinePool, fldPath *field.Path) field.Er | |
} | ||
} | ||
|
||
allErrs = append(allErrs, validateUUIDV4s(p.AdditionalNetworkIDs, fldPath.Child("additionalNetworkIDs"))...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be using the valid values fetcher here to validate that these networks and security groups actually exist in openstack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be done as a part of our Validation epic |
||
allErrs = append(allErrs, validateUUIDV4s(p.AdditionalSecurityGroupIDs, fldPath.Child("additionalSecurityGroupIDs"))...) | ||
|
||
return allErrs | ||
} | ||
|
||
func validateUUIDV4s(input []string, fldPath *field.Path) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
for idx, uuid := range input { | ||
if !validUUIDv4(uuid) { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Index(idx), uuid, "valid UUID v4 must be specified")) | ||
} | ||
} | ||
|
||
return allErrs | ||
} | ||
|
||
// validUUIDv4 checks if string is in UUID v4 format | ||
// For more information: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) | ||
func validUUIDv4(s string) bool { | ||
uuid, err := guuid.Parse(s) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
// check that version of the uuid | ||
if uuid.Version().String() != "VERSION_4" { | ||
return false | ||
} | ||
|
||
return true | ||
} |
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.
You dont have to do this in this patch, but could we just pass the install config here, or make a new struct to pass tfvars? The number of arguments to this function is becoming ludicrous :)
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 know... Abhinav asked the same question #3291 (comment)
But I think we don't have other options, because we need to differenciate between primary and additional objects, and the only way is to read them from the machine pool :(