Move code to pkg
This commit is contained in:
parent
bd4c822670
commit
f1b085fa36
465 changed files with 656 additions and 680 deletions
|
@ -1,37 +0,0 @@
|
|||
package k8s
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/log"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
// MustParseYaml parses a YAML to objects.
|
||||
func MustParseYaml(content []byte) []runtime.Object {
|
||||
acceptedK8sTypes := regexp.MustCompile(`(Deployment|Endpoints|Service|Ingress|IngressRoute|Middleware|Secret)`)
|
||||
|
||||
files := strings.Split(string(content), "---")
|
||||
retVal := make([]runtime.Object, 0, len(files))
|
||||
for _, file := range files {
|
||||
if file == "\n" || file == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||
obj, groupVersionKind, err := decode([]byte(file), nil, nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error while decoding YAML object. Err was: %s", err))
|
||||
}
|
||||
|
||||
if !acceptedK8sTypes.MatchString(groupVersionKind.Kind) {
|
||||
log.WithoutContext().Debugf("The custom-roles configMap contained K8s object types which are not supported! Skipping object with type: %s", groupVersionKind.Kind)
|
||||
} else {
|
||||
retVal = append(retVal, obj)
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue