Skip to content
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

metallb: add metallb controller and speaker builder func #276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gkopels
Copy link
Contributor

@gkopels gkopels commented Mar 19, 2024

This PR adds metallb builder function allowing helm chart fields to be used to populate the controller and speaker config.

@gkopels gkopels requested a review from kononovn as a code owner March 19, 2024 09:29
@gkopels gkopels force-pushed the add-metallb-helmchart-config branch from 4e56eb9 to 26a5684 Compare March 19, 2024 10:41
Effect: "NoExecute",
},
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can define all 3( Spec, ControllerConfig, ControllerTolerations) together.

builder.Definition.Spec = mlbtypes.MetalLBSpec{
	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: "Exists",
			Effect:   "NoExecute",
		},
	},
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Changed

Effect: "NoExecute",
},
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same like above. we can define them together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Copy link
Contributor

@ajaggapa ajaggapa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor suggestions

@@ -392,3 +393,101 @@ func (builder *Builder) convertToStructured(unsObject *unstructured.Unstructured

return metalLb, err
}

// WithMetallbControllerConfig defines the controller config with a helm chart table.
func (builder *Builder) WithMetallbControllerConfig(priorityClassName, runtimeClassName, deploymentName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please this func to other global With functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate all arguments: priorityClassName, runtimeClassName, deploymentName,helmChartControllerTestName, helmChartKeyExample

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at CRD, it seems that priorityClassName, runtimeClassName, are optional fields. Just wonder if is needed to enforce them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are optional. They can also accept an empty string. I have removed the validation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's a good idea, because an empty field and a field that's not configured are not the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I added a verification to make sure its not an empty field

func (builder *Builder) WithMetallbSpeakerConfig(speakerPriorityClassName, runtimeClassName, helmChartDemoSpeakerName,
helmChartSpeakerTestName, keyName string) *Builder {
if valid, err := builder.validate(); !valid {
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

return builder
}

if !builder.Exists() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate all arguments: priorityClassName, runtimeClassName, deploymentName,helmChartControllerTestName, helmChartKeyExample

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for PriorityClassName, RuntimeClassName, those are optional fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also optional and can receive an empty string. Removing the validations

@gkopels gkopels force-pushed the add-metallb-helmchart-config branch 6 times, most recently from be591e3 to 1979312 Compare March 20, 2024 13:09
@ajaggapa
Copy link
Contributor

lgtm

@gkopels gkopels changed the title cnf network: add metallb controller and speaker builder func metallb: add metallb controller and speaker builder func Mar 20, 2024
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return builder here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return builder here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Collaborator

@cdvultur cdvultur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments on optional fields that are required. Wondering if that is really the intent

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at CRD, it seems that priorityClassName, runtimeClassName, are optional fields. Just wonder if is needed to enforce them.

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for PriorityClassName, RuntimeClassName, those are optional fields.

@gkopels gkopels force-pushed the add-metallb-helmchart-config branch 5 times, most recently from 5d52665 to 0b9fa5b Compare March 25, 2024 19:21
cdvultur
cdvultur previously approved these changes Mar 26, 2024
Copy link
Collaborator

@cdvultur cdvultur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@gkopels gkopels force-pushed the add-metallb-helmchart-config branch 3 times, most recently from 7e94f52 to e0ecc15 Compare March 31, 2024 08:52
@gkopels gkopels force-pushed the add-metallb-helmchart-config branch 4 times, most recently from de41b86 to fd722cd Compare April 17, 2024 07:51
@gkopels gkopels force-pushed the add-metallb-helmchart-config branch 5 times, most recently from d6a41b9 to f3976a0 Compare April 18, 2024 05:14
@gkopels gkopels force-pushed the add-metallb-helmchart-config branch from f3976a0 to 6616b87 Compare April 18, 2024 05:17
@@ -326,6 +327,195 @@ func (builder *Builder) WithSpeakerNodeSelector(label map[string]string) *Builde
return builder
}

// WithControllerPriorityClassName adds a priority class name tp the metallb controller config.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be to ?

Suggested change
// WithControllerPriorityClassName adds a priority class name tp the metallb controller config.
// WithControllerPriorityClassName adds a priority class name to the metallb controller config.

return builder
}

// if len(priorityClassName) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented code

PodAffinity: &corev1.PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{"component": controllerPodAffinityLabel},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be more flexible by passing in the map for the MatchLabels and a string parameter for the TopologyKey:

Suggested change
MatchLabels: map[string]string{"component": controllerPodAffinityLabel},
MatchLabels: contollerPodAffinityMap,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants