@@ -28,7 +28,6 @@ import (
28
28
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
29
29
"k8s.io/apimachinery/pkg/runtime"
30
30
"k8s.io/apimachinery/pkg/runtime/schema"
31
- "k8s.io/apimachinery/pkg/util/validation"
32
31
"k8s.io/cli-runtime/pkg/resource"
33
32
)
34
33
@@ -72,11 +71,6 @@ func CreateObjMetadata(namespace string, name string, gk schema.GroupKind) (ObjM
72
71
if name == "" {
73
72
return ObjMetadata {}, fmt .Errorf ("empty name for object" )
74
73
}
75
- // Manually validate name, since by the time k8s reports the error
76
- // the invalid name has already been encoded into the inventory object.
77
- if ! validateNameChars (name , gk ) {
78
- return ObjMetadata {}, fmt .Errorf ("invalid characters in object name: %s" , name )
79
- }
80
74
if gk .Empty () {
81
75
return ObjMetadata {}, fmt .Errorf ("empty GroupKind for object" )
82
76
}
@@ -87,27 +81,6 @@ func CreateObjMetadata(namespace string, name string, gk schema.GroupKind) (ObjM
87
81
}, nil
88
82
}
89
83
90
- // validateNameChars returns false if the passed name is not a valid
91
- // resource name; true otherwise. For almost all resources, the following
92
- // characters are allowed:
93
- //
94
- // Most resource types require a name that can be used as a DNS label name
95
- // as defined in RFC 1123. This means the name must:
96
- //
97
- // * contain no more than 253 characters
98
- // * contain only lowercase alphanumeric characters, '-'
99
- // * start with an alphanumeric character
100
- // * end with an alphanumeric character
101
- //
102
- // For RBAC resources we also allow the colon character.
103
- func validateNameChars (name string , gk schema.GroupKind ) bool {
104
- if _ , exists := RBACGroupKind [gk ]; exists {
105
- name = strings .ReplaceAll (name , ":" , "" )
106
- }
107
- errs := validation .IsDNS1123Subdomain (name )
108
- return len (errs ) == 0
109
- }
110
-
111
84
// ParseObjMetadata takes a string, splits it into its four fields,
112
85
// and returns an ObjMetadata struct storing the four fields.
113
86
// Example inventory string:
@@ -143,6 +116,10 @@ func ParseObjMetadata(s string) (ObjMetadata, error) {
143
116
// Finally, second field name. Name may contain colon transcoded as double underscore.
144
117
name := s [:index ]
145
118
name = strings .ReplaceAll (name , colonTranscoded , ":" )
119
+ // Check that there are no extra fields by search for fieldSeparator.
120
+ if strings .Contains (name , fieldSeparator ) {
121
+ return ObjMetadata {}, fmt .Errorf ("too many fields within: %s" , s )
122
+ }
146
123
// Create the ObjMetadata object from the four parsed fields.
147
124
gk := schema.GroupKind {
148
125
Group : strings .TrimSpace (group ),
0 commit comments