check existence of the same label from node-agent

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2024-12-10 13:44:54 +08:00
parent cce4d4815a
commit 3f31730003
10 changed files with 195 additions and 19 deletions
+20 -1
View File
@@ -38,7 +38,8 @@ const (
)
var (
ErrDaemonSetNotFound = errors.New("daemonset not found")
ErrDaemonSetNotFound = errors.New("daemonset not found")
ErrNodeAgentLabelNotFound = errors.New("node-agent label not found")
)
type LoadConcurrency struct {
@@ -161,3 +162,21 @@ func GetConfigs(ctx context.Context, namespace string, kubeClient kubernetes.Int
return configs, nil
}
func GetLabelValue(ctx context.Context, kubeClient kubernetes.Interface, namespace string, key string) (string, error) {
ds, err := kubeClient.AppsV1().DaemonSets(namespace).Get(ctx, daemonSet, metav1.GetOptions{})
if err != nil {
return "", errors.Wrap(err, "error getting node-agent daemonset")
}
if ds.Spec.Template.Labels == nil {
return "", ErrNodeAgentLabelNotFound
}
val, found := ds.Spec.Template.Labels[key]
if !found {
return "", ErrNodeAgentLabelNotFound
}
return val, nil
}