...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package controller
17
18 import (
19 "strings"
20
21 "github.com/pkg/errors"
22 "k8s.io/apimachinery/pkg/types"
23 )
24
25 func ParseNamespacedName(namespacedName string) (types.NamespacedName, error) {
26 parts := strings.Split(namespacedName, "/")
27 if len(parts) > 1 {
28 return types.NamespacedName{
29 Namespace: parts[0],
30 Name: parts[1],
31 }, nil
32 }
33
34 return types.NamespacedName{
35 Namespace: "",
36 Name: "",
37 }, errors.New("too few parts of namespacedname")
38
39 }
40
41 func ParseNamespacedNameContainer(namespacedName string) (types.NamespacedName, string, error) {
42 parts := strings.Split(namespacedName, "/")
43 if len(parts) > 2 {
44
45
46
47 return types.NamespacedName{
48 Namespace: parts[0],
49 Name: parts[1],
50 }, parts[2], nil
51 }
52
53 return types.NamespacedName{
54 Namespace: "",
55 Name: "",
56 }, "", errors.New("too few parts of namespacedname")
57
58 }
59
60 func ParseNamespacedNameContainerVolumePath(record string) (types.NamespacedName, string, string, error) {
61 parts := strings.Split(record, "/")
62 if len(parts) > 3 {
63 return types.NamespacedName{
64 Namespace: parts[0],
65 Name: parts[1],
66 }, parts[2], strings.Join(parts[3:], "/"), nil
67 }
68
69 return types.NamespacedName{
70 Namespace: "",
71 Name: "",
72 }, "", "", errors.New("too few parts of namespacedname")
73 }
74