Pass GW IP to vino-builder in networks struct
Change-Id: I33e2c855f74b75716dda9e3c081e23c090e7186e
This commit is contained in:
parent
5551ec347a
commit
172b653bad
@ -104,6 +104,7 @@ string
|
||||
</div>
|
||||
<h3 id="airship.airshipit.org/v1.Builder">Builder
|
||||
</h3>
|
||||
<p>TODO (kkalynovskyi) create an API object for this, and refactor vino-builder to read it from kubernetes.</p>
|
||||
<div class="md-typeset__scrollwrap">
|
||||
<div class="md-typeset__table">
|
||||
<table>
|
||||
@ -128,8 +129,8 @@ string
|
||||
<td>
|
||||
<code>networks</code><br>
|
||||
<em>
|
||||
<a href="#airship.airshipit.org/v1.BuilderNetwork">
|
||||
map[string]./pkg/api/v1.BuilderNetwork
|
||||
<a href="#airship.airshipit.org/v1.Network">
|
||||
[]Network
|
||||
</a>
|
||||
</em>
|
||||
</td>
|
||||
@ -158,6 +159,7 @@ map[string]./pkg/api/v1.BuilderDomain
|
||||
(<em>Appears on:</em>
|
||||
<a href="#airship.airshipit.org/v1.Builder">Builder</a>)
|
||||
</p>
|
||||
<p>BuilderDomain represents a VINO libvirt domain</p>
|
||||
<div class="md-typeset__scrollwrap">
|
||||
<div class="md-typeset__table">
|
||||
<table>
|
||||
@ -184,12 +186,6 @@ map[string]./pkg/api/v1.BuilderNetworkInterface
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="airship.airshipit.org/v1.BuilderNetwork">BuilderNetwork
|
||||
</h3>
|
||||
<p>
|
||||
(<em>Appears on:</em>
|
||||
<a href="#airship.airshipit.org/v1.Builder">Builder</a>)
|
||||
</p>
|
||||
<h3 id="airship.airshipit.org/v1.BuilderNetworkInterface">BuilderNetworkInterface
|
||||
</h3>
|
||||
<p>
|
||||
@ -679,6 +675,7 @@ string
|
||||
</h3>
|
||||
<p>
|
||||
(<em>Appears on:</em>
|
||||
<a href="#airship.airshipit.org/v1.Builder">Builder</a>,
|
||||
<a href="#airship.airshipit.org/v1.VinoSpec">VinoSpec</a>)
|
||||
</p>
|
||||
<p>Network defines libvirt networks</p>
|
||||
|
@ -16,20 +16,18 @@ limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
// TODO (kkalynovskyi) create an API object for this, and refactor vino-builder to read it from kubernetes.
|
||||
type Builder struct {
|
||||
GWIPBridge string `json:"gwIPBridge,omitempty"`
|
||||
Networks map[string]BuilderNetwork `json:"networks,omitempty"`
|
||||
Domains map[string]BuilderDomain `json:"domains,omitempty"`
|
||||
GWIPBridge string `json:"gwIPBridge,omitempty"`
|
||||
Networks []Network `json:"networks,omitempty"`
|
||||
Domains map[string]BuilderDomain `json:"domains,omitempty"`
|
||||
}
|
||||
|
||||
type BuilderNetworkInterface struct {
|
||||
MACAddress string `json:"macAddress,omitempty"`
|
||||
}
|
||||
|
||||
type BuilderNetwork struct {
|
||||
// Placeholder for future development
|
||||
}
|
||||
|
||||
// BuilderDomain represents a VINO libvirt domain
|
||||
type BuilderDomain struct {
|
||||
Interfaces map[string]BuilderNetworkInterface `json:"interfaces,omitempty"`
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ func (in *Builder) DeepCopyInto(out *Builder) {
|
||||
*out = *in
|
||||
if in.Networks != nil {
|
||||
in, out := &in.Networks, &out.Networks
|
||||
*out = make(map[string]BuilderNetwork, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
*out = make([]Network, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.Domains != nil {
|
||||
@ -106,21 +106,6 @@ func (in *BuilderDomain) DeepCopy() *BuilderDomain {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *BuilderNetwork) DeepCopyInto(out *BuilderNetwork) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BuilderNetwork.
|
||||
func (in *BuilderNetwork) DeepCopy() *BuilderNetwork {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(BuilderNetwork)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *BuilderNetworkInterface) DeepCopyInto(out *BuilderNetworkInterface) {
|
||||
*out = *in
|
||||
|
@ -156,7 +156,7 @@ func (r *VinoReconciler) createBMHperPod(ctx context.Context, vino *vinov1.Vino,
|
||||
return err
|
||||
}
|
||||
|
||||
ip, err := r.getBridgeIP(ctx, k8sNode)
|
||||
nodeNetworks, err := r.nodeNetworks(ctx, vino.Spec.Networks, k8sNode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -173,13 +173,14 @@ func (r *VinoReconciler) createBMHperPod(ctx context.Context, vino *vinov1.Vino,
|
||||
return nodeErr
|
||||
}
|
||||
|
||||
values, nodeErr := r.networkValues(ctx, bmhName, ip, node, vino)
|
||||
domainNetValues, nodeErr := r.domainSpecificNetValues(ctx, bmhName, node, nodeNetworks)
|
||||
if nodeErr != nil {
|
||||
return nodeErr
|
||||
}
|
||||
nodeNetworkValues[roleSuffix] = values.Generated
|
||||
// save domain specific generated values to a map
|
||||
nodeNetworkValues[roleSuffix] = domainNetValues.Generated
|
||||
|
||||
netData, netDataNs, nodeErr := r.reconcileBMHNetworkData(ctx, node, vino, values)
|
||||
netData, netDataNs, nodeErr := r.reconcileBMHNetworkData(ctx, node, vino, domainNetValues)
|
||||
if nodeErr != nil {
|
||||
return nodeErr
|
||||
}
|
||||
@ -197,9 +198,7 @@ func (r *VinoReconciler) createBMHperPod(ctx context.Context, vino *vinov1.Vino,
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: bmhName,
|
||||
Namespace: getRuntimeNamespace(),
|
||||
// TODO add rack and server labels, when we crearly define mechanism
|
||||
// which labels we are copying
|
||||
Labels: labels,
|
||||
Labels: labels,
|
||||
},
|
||||
Spec: metal3.BareMetalHostSpec{
|
||||
NetworkData: &corev1.SecretReference{
|
||||
@ -221,19 +220,38 @@ func (r *VinoReconciler) createBMHperPod(ctx context.Context, vino *vinov1.Vino,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("annotating node", "node", k8sNode.Name)
|
||||
if err = r.annotateNode(ctx, ip, k8sNode, nodeNetworkValues); err != nil {
|
||||
if err = r.annotateNode(ctx, k8sNode, nodeNetworkValues, nodeNetworks); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *VinoReconciler) networkValues(
|
||||
// nodeNetworks returns a copy of node network with a unique per node values
|
||||
func (r *VinoReconciler) nodeNetworks(ctx context.Context,
|
||||
globalNetworks []vinov1.Network,
|
||||
k8sNode *corev1.Node) ([]vinov1.Network, error) {
|
||||
bridgeIP, err := r.getBridgeIP(ctx, k8sNode)
|
||||
if err != nil {
|
||||
return []vinov1.Network{}, err
|
||||
}
|
||||
|
||||
for netIndex, network := range globalNetworks {
|
||||
for routeIndex, route := range network.Routes {
|
||||
if route.Gateway == "$vinobridge" {
|
||||
globalNetworks[netIndex].Routes[routeIndex].Gateway = bridgeIP
|
||||
}
|
||||
}
|
||||
}
|
||||
return globalNetworks, nil
|
||||
}
|
||||
|
||||
func (r *VinoReconciler) domainSpecificNetValues(
|
||||
ctx context.Context,
|
||||
bmhName string,
|
||||
bridgeIP string,
|
||||
node vinov1.NodeSet,
|
||||
vino *vinov1.Vino) (networkTemplateValues, error) {
|
||||
networks []vinov1.Network) (networkTemplateValues, error) {
|
||||
// Allocate an IP for each of this BMH's network interfaces
|
||||
ipAddresses := map[string]string{}
|
||||
macAddresses := map[string]string{}
|
||||
@ -242,12 +260,7 @@ func (r *VinoReconciler) networkValues(
|
||||
subnet := ""
|
||||
var err error
|
||||
subnetRange := vinov1.Range{}
|
||||
for netIndex, network := range vino.Spec.Networks {
|
||||
for routeIndex, route := range network.Routes {
|
||||
if route.Gateway == "$vinobridge" {
|
||||
vino.Spec.Networks[netIndex].Routes[routeIndex].Gateway = bridgeIP
|
||||
}
|
||||
}
|
||||
for _, network := range networks {
|
||||
if network.Name == networkName {
|
||||
subnet = network.SubNet
|
||||
subnetRange, err = ipam.NewRange(network.AllocationStart,
|
||||
@ -274,7 +287,7 @@ func (r *VinoReconciler) networkValues(
|
||||
return networkTemplateValues{
|
||||
Node: node,
|
||||
BMHName: bmhName,
|
||||
Networks: vino.Spec.Networks,
|
||||
Networks: networks,
|
||||
Generated: generatedValues{
|
||||
IPAddresses: ipAddresses,
|
||||
MACAddresses: macAddresses,
|
||||
@ -283,15 +296,15 @@ func (r *VinoReconciler) networkValues(
|
||||
}
|
||||
|
||||
func (r *VinoReconciler) annotateNode(ctx context.Context,
|
||||
gwIP string,
|
||||
k8sNode *corev1.Node,
|
||||
values map[string]generatedValues) error {
|
||||
domainInterfaceValues map[string]generatedValues,
|
||||
networks []vinov1.Network) error {
|
||||
logr.FromContext(ctx).Info("Getting GW bridge IP from node", "node", k8sNode.Name)
|
||||
builderValues := vinov1.Builder{
|
||||
Domains: make(map[string]vinov1.BuilderDomain),
|
||||
GWIPBridge: gwIP,
|
||||
Domains: make(map[string]vinov1.BuilderDomain),
|
||||
Networks: networks,
|
||||
}
|
||||
for domainName, domain := range values {
|
||||
for domainName, domain := range domainInterfaceValues {
|
||||
builderDomain := vinov1.BuilderDomain{
|
||||
Interfaces: make(map[string]vinov1.BuilderNetworkInterface),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user