Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/utils/getters/k8sGetters.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
liqolabels "github.com/liqotech/liqo/pkg/utils/labels"
"github.com/liqotech/liqo/pkg/utils/resource"
vkforge "github.com/liqotech/liqo/pkg/vkMachinery/forge"
)

Expand Down Expand Up @@ -463,7 +464,7 @@ func GetKubeconfigSecretFromIdentity(ctx context.Context, cl client.Client, iden
// ListShadowPodsByCreator returns the list of ShadowPods created by the given user.
func ListShadowPodsByCreator(ctx context.Context, cl client.Client, creator string) (*offloadingv1beta1.ShadowPodList, error) {
list := new(offloadingv1beta1.ShadowPodList)
if err := cl.List(ctx, list, client.MatchingLabels{consts.CreatorLabelKey: creator}); err != nil {
if err := cl.List(ctx, list, client.MatchingLabels{consts.CreatorLabelKey: resource.EscapeLabel(creator)}); err != nil {
return nil, err
}
return list, nil
Expand All @@ -479,7 +480,7 @@ func GetQuotaByUser(ctx context.Context, cl client.Client,
}

for i := range quotas.Items {
if quotas.Items[i].Spec.User == user {
if resource.EscapeLabel(quotas.Items[i].Spec.User) == user {
return &quotas.Items[i], nil
}
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/utils/resource/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package resource

import (
"maps"
"regexp"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
// globalLabels stores the global labels that should be added to all resources.
globalLabels = make(map[string]string)
globalLabels = make(map[string]string)
regexLabelEscape = regexp.MustCompile(`[^\w\-.]`)
)

// SetGlobalLabels sets the global labels that should be added to all resources.
Expand All @@ -47,3 +49,8 @@ func AddGlobalLabels(obj metav1.Object) {
}
maps.Copy(obj.GetLabels(), globalLabels)
}

// EscapeLabel escapes a label value so that it is compliant.
func EscapeLabel(val string) string {
return regexLabelEscape.ReplaceAllString(val, "-")
}
3 changes: 2 additions & 1 deletion pkg/webhooks/shadowpod/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/utils/getters"
pod "github.com/liqotech/liqo/pkg/utils/pod"
"github.com/liqotech/liqo/pkg/utils/resource"
"github.com/liqotech/liqo/pkg/virtualKubelet/forge"
)

Expand Down Expand Up @@ -357,7 +358,7 @@ func (spm *Mutator) HandleDelete() admission.Response {
}

func extractCreatorInfo(userInfo *authenticationv1.UserInfo) (creatorName string, err error) {
creatorName = userInfo.Username
creatorName = resource.EscapeLabel(userInfo.Username)
if creatorName == "" {
return "", fmt.Errorf("missing creator name")
}
Expand Down