From e8688c5606806cdbba5d25a2497cda766d24e1b7 Mon Sep 17 00:00:00 2001 From: Rodolfo Pacheco Date: Wed, 28 Oct 2020 11:54:00 -0400 Subject: [PATCH] WIP: Fixed sample CR --- .../samples/airship_v1beta1_sipcluster.yaml | 52 +++++++++++-------- pkg/api/v1/sipcluster_types.go | 43 ++------------- pkg/vbmh/machines.go | 32 +++++++----- 3 files changed, 53 insertions(+), 74 deletions(-) diff --git a/config/samples/airship_v1beta1_sipcluster.yaml b/config/samples/airship_v1beta1_sipcluster.yaml index d5cddb4..519dc63 100644 --- a/config/samples/airship_v1beta1_sipcluster.yaml +++ b/config/samples/airship_v1beta1_sipcluster.yaml @@ -5,31 +5,39 @@ metadata: namespace: clusterA spec: nodes: - - vm-role: 'worker' - vm-flavor: 'foobar' - scheduling-constraints: ['per-node'] # Support dont'care option. - count: - active: 3 #driven by capi node number - standby: 1 #slew for upgrades etc - - vm-role: 'master' - vm-flavor: 'goober' - scheduling-constraints: ['per-node','per-rack'] - count: - active: 3 - standby: 1 + worker: + vm-flavor: 'airshipit.org/vino-flavor=worker' + scheduling-constraints: ['per-node'] # Support dont'care option. + count: + active: 3 #driven by capi node number + standby: 1 #slew for upgrades etc + master: + vm-flavor: 'airshipit.org/vino-flavor=master' + scheduling-constraints: ['per-node','per-rack'] + count: + active: 3 + standby: 1 infra: loadbalancer: + optional: clusterIp: 1.2.3.4 #<-- this aligns to the VIP IP for undercloud k8s - image: haproxy:foo - nodeLabels: + image: haproxy:foo + nodeLabels: - airship-masters - nodePort: 7000 - nodeInterfaceId: oam-ipv4 - jump: + nodePort: 7000 + nodeInterfaceId: oam-ipv4 + jumppod: + optional: sshKey: rsa.... #<-- this needs to align to the ssh keys provided to cluster api objects - image: sshpod:foo - nodeLabels: - - airship-masters - nodePort: 7022 - nodeInterfaceId: oam-ipv4 + image: sshpod:foo + nodeLabels: + - airship-masters + nodePort: 7022 + nodeInterfaceId: oam-ipv4 + authpod: + image: sshpod:foo + nodeLabels: + - airship-masters + nodePort: 7022 + nodeInterfaceId: oam-ipv4 diff --git a/pkg/api/v1/sipcluster_types.go b/pkg/api/v1/sipcluster_types.go index cc71dfa..00716e5 100644 --- a/pkg/api/v1/sipcluster_types.go +++ b/pkg/api/v1/sipcluster_types.go @@ -49,13 +49,13 @@ type InfraService string // Possible Infra Structure Services const ( // LoadBalancer Service - LoadBalancerService InfraService = "LoadBalancer" + LoadBalancerService InfraService = "loadbalancer" // JumpHostService Service - JumpHostService InfraService = "JumpHost" + JumpHostService InfraService = "jumppod" // AuthHostService Service - AuthHostService InfraService = "AuthHost" + AuthHostService InfraService = "authpod" ) // NodeSet are the the list of Nodes objects workers, @@ -87,45 +87,12 @@ type SchedulingOptions string // Possible Node or VM Roles for a Tenant const ( // RackAntiAffinity means the state is unknown - RackAntiAffinity SchedulingOptions = "rack" + RackAntiAffinity SchedulingOptions = "per-rack" // ServerAntiAffinity means the state is unknown - ServerAntiAffinity SchedulingOptions = "server" + ServerAntiAffinity SchedulingOptions = "per-node" ) -/* -type InfraSet struct { - // Load Balancer Infrastrcture Service that fronts a Tenant Cluster - // Kubernetes API Servers - // These provides the configuration expectations - LoadBalancer *LoadBalancerConfig `json:"loadbalancer,omitempty"` - // Jump Host is an Operation POD that allows operators to - // Manage the VM Node infrastcuture - // These provides the configuration expectations - JumpHost *JumpHostConfig `json:"jumphost,omitempty"` - // AuthHost is an Service POD that provides an OIDC provider - // interface to the Tenant Cluster - // These provides the configuration expectations - AuthHost *AuthConfig `json:"authhost,omitempty"` - -} -*/ -/* -type LoadBalancerConfig struct { - ClusterIp string `json:"clusterIp,omitempty"` - Config *InfraConfig `json:"config,omitempty"` -} - -type JumpHostConfig struct { - SshKey string `json:"sshkey,omitempty"` - Config *InfraConfig `json:"config,omitempty"` -} - -type AuthConfig struct { - Config *InfraConfig `json:"config,omitempty"` -} -*/ - type InfraConfig struct { OptionalData *OptsConfig `json:"optional,omitempty"` Image string `json:"image,omitempty"` diff --git a/pkg/vbmh/machines.go b/pkg/vbmh/machines.go index 8318893..7dc1b17 100644 --- a/pkg/vbmh/machines.go +++ b/pkg/vbmh/machines.go @@ -21,6 +21,7 @@ import ( metal3 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "sigs.k8s.io/controller-runtime/pkg/client" airshipv1 "sipcluster/pkg/api/v1" + "strings" //corev1 "k8s.io/api/core/v1" //rbacv1 "k8s.io/api/rbac/v1" //"k8s.io/apimachinery/pkg/api/errors" @@ -161,16 +162,16 @@ func (ml *MachineList) initScheduleMaps(constraints []airshipv1.SchedulingOption for _, constraint := range constraints { if constraint == airshipv1.RackAntiAffinity { setMap[constraint] = &ScheduleSet{ - active: true, - set: make(map[string]bool), - label: RackLabel, + active: true, + set: make(map[string]bool), + labelName: RackLabel, } } if constraint == airshipv1.ServerAntiAffinity { setMap[constraint] = &ScheduleSet{ - active: true, - set: make(map[string]bool), - label: ServerLabel, + active: true, + set: make(map[string]bool), + labelName: ServerLabel, } } } @@ -192,9 +193,9 @@ func (ml *MachineList) scheduleIt(nodeRole airshipv1.VmRoles, nodeCfg airshipv1. // Check if bmh has the label // There is a func (host *BareMetalHost) getLabel(name string) string { // Not sure why its not Public, so sing our won method - cLabelValue, cFlavorValue := scheduleSetMap[constraint].GetLabels(bmh.Labels, nodeCfg.VmFlavor) + cLabelValue, cFlavorMatches := scheduleSetMap[constraint].GetLabels(bmh.Labels, nodeCfg.VmFlavor) - if cLabelValue != "" && cFlavorValue != "" { + if cLabelValue != "" && cFlavorMatches { // If its in th elist , theen this bmh is disqualified. Skip it if scheduleSetMap[constraint].Exists(cLabelValue) { validBmh = false @@ -236,8 +237,8 @@ type ScheduleSet struct { active bool // Holds list of elements in teh Set set map[string]bool - // Holds the label that identifies the constraint - label string + // Holds the label name that identifies the constraint + labelName string } func (ss *ScheduleSet) Active() bool { @@ -250,10 +251,13 @@ func (ss *ScheduleSet) Exists(value string) bool { return false } -func (ss *ScheduleSet) GetLabels(labels map[string]string, customLabel string) (string, string) { +func (ss *ScheduleSet) GetLabels(labels map[string]string, flavorLabel string) (string, bool) { if labels == nil { - return "", "" + return "", false } - return labels[ss.label], labels[customLabel] - + cl := strings.Split(flavorLabel, "=") + if len(cl) > 0 { + return labels[ss.labelName], labels[cl[0]] == cl[1] + } + return labels[ss.labelName], false }