Skip to content

Commit

Permalink
cnf network: add metallb controller and speaker builder func
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Kopels committed Mar 20, 2024
1 parent c1448ca commit be591e3
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions pkg/metallb/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package metallb
import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"

"github.com/golang/glog"
"github.com/openshift-kni/eco-goinfra/pkg/clients"
Expand Down Expand Up @@ -314,6 +315,163 @@ func (builder *Builder) WithSpeakerNodeSelector(label map[string]string) *Builde
return builder
}

// WithMetallbControllerConfig defines the controller config with a helm chart table.
func (builder *Builder) WithMetallbControllerConfig(priorityClassName, runtimeClassName, deploymentName,
helmChartControllerTestName, helmChartKeyExample string) *Builder {
if valid, _ := builder.validate(); !valid {
return builder
}

if !builder.Exists() {
glog.V(100).Infof("failed to update metallb, object doesn't exist on cluster")
}

glog.V(100).Infof("Defining the metallb object with Helm Chart in namespace %s",
builder.Definition.Namespace,
)

if priorityClassName == "" {
glog.V(100).Infof("The controller config priorityClassName is empty")

builder.errorMsg = "controller config priorityClassName cannot be empty"
}

if runtimeClassName == "" {
glog.V(100).Infof("The controller config runtimeClassName is empty")

builder.errorMsg = "controller config runtimeClassName cannot be empty"
}

if deploymentName == "" {
glog.V(100).Infof("The controller config deploymentName is empty")

builder.errorMsg = "controller config deploymentName cannot be empty"
}

if helmChartControllerTestName == "" {
glog.V(100).Infof("The controller config helmChartControllerTestName is empty")

builder.errorMsg = "controller config helmChartControllerTestName cannot be empty"
}

if helmChartKeyExample == "" {
glog.V(100).Infof("The controller config helmChartKeyExample is empty")

builder.errorMsg = "controller config helmChartKeyExample cannot be empty"
}

if builder.errorMsg != "" {
glog.V(100).Infof("Error occurred building metallb Controller Config")
}
builder.Definition.Spec = mlbtypes.MetalLBSpec{

Check failure on line 366 in pkg/metallb/metallb.go

View workflow job for this annotation

GitHub Actions / build

assignments should only be cuddled with other assignments (wsl)
ControllerConfig: &mlbtypes.Config{
PriorityClassName: priorityClassName,
RuntimeClassName: runtimeClassName,
Annotations: map[string]string{deploymentName: "controller"},
Affinity: &corev1.Affinity{
PodAffinity: &corev1.PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{LabelSelector: &metaV1.LabelSelector{
MatchLabels: map[string]string{"component": helmChartControllerTestName},
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
},
ControllerTolerations: []corev1.Toleration{
{
Key: helmChartKeyExample,
Operator: "exist",
Effect: "NoExecute"},
},
}

return builder
}

// WithMetallbSpeakerConfig defines the speaker config with a helm chart table.
func (builder *Builder) WithMetallbSpeakerConfig(speakerPriorityClassName, runtimeClassName, helmChartDemoSpeakerName,
helmChartSpeakerTestName, keyName string) *Builder {
if valid, err := builder.validate(); !valid {
if err != nil {
glog.V(100).Infof("Error occurred validating the metallb Speaker Config")
}

return builder
}

if !builder.Exists() {
glog.V(100).Infof("failed to update metallb, object doesn't exist on cluster")
}

glog.V(100).Infof("Defining the metallb object with Helm Chart in namespace %s",
builder.Definition.Namespace,
)

if speakerPriorityClassName == "" {
glog.V(100).Infof("The speaker config speakerPriorityClassName is empty")

builder.errorMsg = "speaker config speakerPriorityClassName cannot be empty"
}

if runtimeClassName == "" {
glog.V(100).Infof("The speaker config runtimeClassName is empty")

builder.errorMsg = "speaker config runtimeClassName cannot be empty"
}

if helmChartDemoSpeakerName == "" {
glog.V(100).Infof("The speaker config helmChartDemoSpeakerName is empty")

builder.errorMsg = "speaker config helmChartDemoSpeakerName cannot be empty"
}

if helmChartSpeakerTestName == "" {
glog.V(100).Infof("The speaker config helmChartSpeakerTestName is empty")

builder.errorMsg = "speaker config helmChartSpeakerTestName cannot be empty"
}

if keyName == "" {
glog.V(100).Infof("The speaker config keyName is empty")

builder.errorMsg = "speaker config keyName cannot be empty"
}

if builder.errorMsg != "" {
glog.V(100).Infof("Error occurred building metallb Controller Config")
}

builder.Definition.Spec = mlbtypes.MetalLBSpec{
SpeakerConfig: &mlbtypes.Config{PriorityClassName: speakerPriorityClassName, RuntimeClassName: runtimeClassName,
Annotations: map[string]string{"controller": helmChartDemoSpeakerName},
Affinity: &corev1.Affinity{PodAffinity: &corev1.PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{LabelSelector: &metaV1.LabelSelector{
MatchLabels: map[string]string{
"component": helmChartSpeakerTestName,
},
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
},
SpeakerTolerations: []corev1.Toleration{
{
Key: keyName,
Operator: "Exists",
Effect: "NoExecute",
},
},
}

return builder
}

// WithOptions creates metallb with generic mutation options.
func (builder *Builder) WithOptions(options ...AdditionalOptions) *Builder {
if valid, _ := builder.validate(); !valid {
Expand Down

0 comments on commit be591e3

Please sign in to comment.