@@ -28,7 +28,6 @@ import (
2828 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2929 "k8s.io/apimachinery/pkg/runtime"
3030 "k8s.io/apimachinery/pkg/runtime/schema"
31- "k8s.io/apimachinery/pkg/util/validation"
3231 "k8s.io/cli-runtime/pkg/resource"
3332)
3433
@@ -72,11 +71,6 @@ func CreateObjMetadata(namespace string, name string, gk schema.GroupKind) (ObjM
7271 if name == "" {
7372 return ObjMetadata {}, fmt .Errorf ("empty name for object" )
7473 }
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- }
8074 if gk .Empty () {
8175 return ObjMetadata {}, fmt .Errorf ("empty GroupKind for object" )
8276 }
@@ -87,27 +81,6 @@ func CreateObjMetadata(namespace string, name string, gk schema.GroupKind) (ObjM
8781 }, nil
8882}
8983
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-
11184// ParseObjMetadata takes a string, splits it into its four fields,
11285// and returns an ObjMetadata struct storing the four fields.
11386// Example inventory string:
@@ -143,6 +116,10 @@ func ParseObjMetadata(s string) (ObjMetadata, error) {
143116 // Finally, second field name. Name may contain colon transcoded as double underscore.
144117 name := s [:index ]
145118 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+ }
146123 // Create the ObjMetadata object from the four parsed fields.
147124 gk := schema.GroupKind {
148125 Group : strings .TrimSpace (group ),
0 commit comments