@ -4,11 +4,11 @@ import (
"bytes"
"fmt"
"io"
"regexp"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/portainer/portainer/api/stacks/stackutils"
"gopkg.in/yaml.v3"
)
@ -28,19 +28,13 @@ type KubeAppLabels struct {
Kind string
}
// convert string to valid kubernetes label by replacing invalid characters with periods
func sanitizeLabel ( value string ) string {
re := regexp . MustCompile ( ` [^A-Za-z0-9\.\-\_]+ ` )
return re . ReplaceAllString ( value , "." )
}
// ToMap converts KubeAppLabels to a map[string]string
func ( kal * KubeAppLabels ) ToMap ( ) map [ string ] string {
return map [ string ] string {
labelPortainerAppStackID : strconv . Itoa ( kal . StackID ) ,
labelPortainerAppStack : kal. StackName ,
labelPortainerAppName : kal. StackName ,
labelPortainerAppOwner : s anitizeLabel( kal . Owner ) ,
labelPortainerAppStack : stackutils . SanitizeLabel ( kal . StackName ) ,
labelPortainerAppName : stackutils . SanitizeLabel ( kal . StackName ) ,
labelPortainerAppOwner : stackutils . S anitizeLabel( kal . Owner ) ,
labelPortainerAppKind : kal . Kind ,
}
}
@ -49,7 +43,7 @@ func (kal *KubeAppLabels) ToMap() map[string]string {
func GetHelmAppLabels ( name , owner string ) map [ string ] string {
return map [ string ] string {
labelPortainerAppName : name ,
labelPortainerAppOwner : s anitizeLabel( owner ) ,
labelPortainerAppOwner : stackutils . S anitizeLabel( owner ) ,
}
}