@ -4,11 +4,11 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"io"
"io"
"regexp"
"strconv"
"strconv"
"strings"
"strings"
"github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/portainer/portainer/api/stacks/stackutils"
"gopkg.in/yaml.v3"
"gopkg.in/yaml.v3"
)
)
@ -28,19 +28,13 @@ type KubeAppLabels struct {
Kind string
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
// ToMap converts KubeAppLabels to a map[string]string
func ( kal * KubeAppLabels ) ToMap ( ) map [ string ] string {
func ( kal * KubeAppLabels ) ToMap ( ) map [ string ] string {
return map [ string ] string {
return map [ string ] string {
labelPortainerAppStackID : strconv . Itoa ( kal . StackID ) ,
labelPortainerAppStackID : strconv . Itoa ( kal . StackID ) ,
labelPortainerAppStack : kal. StackName ,
labelPortainerAppStack : stackutils . SanitizeLabel ( kal . StackName ) ,
labelPortainerAppName : kal. StackName ,
labelPortainerAppName : stackutils . SanitizeLabel ( kal . StackName ) ,
labelPortainerAppOwner : s anitizeLabel( kal . Owner ) ,
labelPortainerAppOwner : stackutils . S anitizeLabel( kal . Owner ) ,
labelPortainerAppKind : kal . Kind ,
labelPortainerAppKind : kal . Kind ,
}
}
}
}
@ -49,7 +43,7 @@ func (kal *KubeAppLabels) ToMap() map[string]string {
func GetHelmAppLabels ( name , owner string ) map [ string ] string {
func GetHelmAppLabels ( name , owner string ) map [ string ] string {
return map [ string ] string {
return map [ string ] string {
labelPortainerAppName : name ,
labelPortainerAppName : name ,
labelPortainerAppOwner : s anitizeLabel( owner ) ,
labelPortainerAppOwner : stackutils . S anitizeLabel( owner ) ,
}
}
}
}