Skip to content

Commit

Permalink
ON-15464: Recommended Labels and onload-version change
Browse files Browse the repository at this point in the history
* Namespaced the `onload-version` label
* Added `/part-of` and `/managed-by` labels for easier troubleshooting
  selection. Also added `/component` and `/instance` for clarity.
* Renamed `onload-onload-device-plugin-init` to just `init` as name
  need only be unique within pod
* Removed redundant test target from `make device-plugin-docker-push`
  • Loading branch information
pcolledg-amd committed Jan 17, 2024
1 parent e1bbd22 commit 98cf1bc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ device-plugin-docker-build: test ## Build docker image with the manager.
docker build -t ${DEVICE_IMG} -f deviceplugin.Dockerfile --network="host" .

.PHONY: device-plugin-docker-push
device-plugin-docker-push: test ## Push docker image to the registry.
device-plugin-docker-push: ## Push docker image to the registry.
docker push ${DEVICE_IMG}

.PHONY: sfc-mc-docker-build
Expand Down
4 changes: 2 additions & 2 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace: onload-operator-system
namePrefix: onload-operator-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
commonLabels:
app.kubernetes.io/part-of: onload

resources:
- ../crd
Expand Down
3 changes: 3 additions & 0 deletions config/samples/onload/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ resources:
- onload_v1alpha1_onload.yaml
#+kubebuilder:scaffold:manifestskustomizesamples

commonLabels:
app.kubernetes.io/part-of: onload

configurations:
- configurations.yaml
28 changes: 21 additions & 7 deletions controllers/onload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ const kmmModuleLabelPrefix = "kmm.node.kubernetes.io/version-module"
const onloadModuleNameSuffix = "-module"
const sfcModuleNameSuffix = "-sfcmod"

func baseLabels(name, namespace string, component string) map[string]string {
return map[string]string{
"app.kubernetes.io/managed-by": "onload-operator",
"app.kubernetes.io/part-of": "onload",
"app.kubernetes.io/instance": "onload-" + namespace + "-" + name,
"app.kubernetes.io/component": component,
}
}

func kmmOnloadLabelName(name, namespace string) string {
return kmmModuleLabelPrefix + "." + namespace + "." + name + onloadModuleNameSuffix
}
Expand Down Expand Up @@ -553,7 +562,7 @@ func (r *OnloadReconciler) handleNodeUpdate(ctx context.Context, onload *onloadv

// Check that the Device Plugin pod has terminated before continuing
labelSet := labels.Set{
"onload.amd.com/name": onload.Name + devicePluginNameSuffix,
onloadLabelPrefix + "name": onload.Name + devicePluginNameSuffix,
}
pods, err := r.getPodsOnNode(ctx, labelSet, node.Name)
if err != nil {
Expand Down Expand Up @@ -843,6 +852,7 @@ func createModule(
ObjectMeta: metav1.ObjectMeta{
Name: moduleName,
Namespace: onload.Namespace,
Labels: baseLabels(onload.Name, onload.Namespace, "module"),
},
Spec: kmm.ModuleSpec{
ModuleLoader: kmm.ModuleLoaderSpec{
Expand All @@ -867,7 +877,7 @@ func createModule(
}

const devicePluginNameSuffix = "-onload-device-plugin-ds"
const onloadVersionLabel = "onload-version"
const onloadVersionLabel = onloadLabelPrefix + "version"

func (r *OnloadReconciler) createDevicePluginDaemonSet(
ctx context.Context, onload *onloadv1alpha1.Onload,
Expand Down Expand Up @@ -1045,7 +1055,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
}

initContainer := corev1.Container{
Name: onload.Name + "-onload-device-plugin" + "-init",
Name: "init",
Image: onload.Spec.Onload.UserImage,
ImagePullPolicy: onload.Spec.Onload.ImagePullPolicy,
Command: []string{
Expand Down Expand Up @@ -1080,7 +1090,11 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
},
}

dsLabels := map[string]string{"onload.amd.com/name": devicePluginName}
dsLabels := baseLabels(onload.Name, onload.Namespace, "device-plugin")
dsLabels[onloadVersionLabel] = onload.Spec.Onload.Version

dsPodLabels := baseLabels(onload.Name, onload.Namespace, "device-plugin")
dsPodLabels[onloadLabelPrefix+"name"] = devicePluginName

kubeletSocketVolume := corev1.Volume{
Name: "kubelet-socket",
Expand Down Expand Up @@ -1115,14 +1129,14 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
ObjectMeta: metav1.ObjectMeta{
Name: devicePluginName,
Namespace: onload.Namespace,
Labels: map[string]string{onloadVersionLabel: onload.Spec.Onload.Version},
Labels: dsLabels,
},
Spec: appsv1.DaemonSetSpec{
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{Type: appsv1.OnDeleteDaemonSetStrategyType},
Selector: &metav1.LabelSelector{MatchLabels: dsLabels},
Selector: &metav1.LabelSelector{MatchLabels: dsPodLabels},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: dsLabels,
Labels: dsPodLabels,
},
Spec: corev1.PodSpec{
ServiceAccountName: onload.Spec.ServiceAccountName,
Expand Down
1 change: 1 addition & 0 deletions scripts/machineconfig/99-sfc-machineconfig.bu
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
name: 99-sfc-machineconfig
labels:
machineconfiguration.openshift.io/role: SED_NODE_TYPE
app.kubernetes.io/part-of: onload
systemd:
units:
- name: sfc-replace-kernel-module.service
Expand Down
2 changes: 2 additions & 0 deletions scripts/profiles/profile_to_configmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ for profile in $profiles; do
echo "kind: ConfigMap"
echo "metadata:"
echo " name: onload-$(basename "$profile" .opf)-profile"
echo " labels:"
echo " app.kubernetes.io/part-of: onload"
echo "data:"
onload_import "$profile" "$@"
echo "---"
Expand Down

0 comments on commit 98cf1bc

Please sign in to comment.