lingsamuel commented on code in PR #1103:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/1103#discussion_r911688143


##########
test/e2e/scaffold/scaffold.go:
##########
@@ -583,11 +613,40 @@ func (s *Scaffold) CreateVersionedApisixPluginConfig(yml 
string) error {
        return s.CreateResourceFromString(ac)
 }
 
-func (s *Scaffold) CreateVersionedApisixRoute(yml string) error {
-       if !strings.Contains(yml, "kind: ApisixRoute") {
-               return errors.New("not a ApisixRoute")
-       }
-
-       ac := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
-       return s.CreateResourceFromString(ac)
+func (s *Scaffold) CreateVersionedApisixResource(yml string) error {
+       kindValue := s.getKindValue(yml)
+       switch kindValue {
+       case "ApisixRoute":
+               ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
+               return s.CreateResourceFromString(ar)
+       case "ApisixConsumer":
+               ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
+               return s.CreateResourceFromString(ac)
+       case "ApisixPluginConfig":
+               apc := s.replaceApiVersion(yml, 
s.opts.ApisixPluginConfigVersion)
+               return s.CreateResourceFromString(apc)
+       }
+       errString := fmt.Sprint("the resource ", kindValue, " does not support")
+       return errors.New(errString)
+}
+
+func (s *Scaffold) CreateVersionedApisixResourceWithNamespace(yml, namespace 
string) error {
+       kindValue := s.getKindValue(yml)
+       switch kindValue {
+       case "ApisixRoute":
+               ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
+               return s.CreateResourceFromStringWithNamespace(ar, namespace)
+       case "ApisixConsumer":
+               ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
+               return s.CreateResourceFromStringWithNamespace(ac, namespace)
+       case "ApisixPluginConfig":
+               apc := s.replaceApiVersion(yml, 
s.opts.ApisixPluginConfigVersion)
+               return s.CreateResourceFromStringWithNamespace(apc, namespace)
+       }
+       errString := fmt.Sprint("the resource ", kindValue, " does not support")
+       return errors.New(errString)

Review Comment:
   `fmt.Errorf`



##########
test/e2e/scaffold/scaffold.go:
##########
@@ -541,12 +564,19 @@ func (s *Scaffold) FormatNamespaceLabel(label string) 
string {
 
 var (
        versionRegex = regexp.MustCompile(`apiVersion: 
apisix.apache.org/v.*?\n`)
+       kindRegex    = regexp.MustCompile(`kind: .*?\n`)
 )
 
 func (s *Scaffold) replaceApiVersion(yml, ver string) string {
        return versionRegex.ReplaceAllString(yml, "apiVersion: "+ver+"\n")
 }
 
+func (s *Scaffold) getKindValue(yml string) string {
+       kind := strings.Replace(kindRegex.FindString(yml), "\n", "", -1)

Review Comment:
   Why not use capture groups?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to