Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the branch name of devop is Chinese, an error will be reported #104

Closed
yyt6200 opened this issue Jul 5, 2021 · 15 comments · Fixed by #328
Closed

When the branch name of devop is Chinese, an error will be reported #104

yyt6200 opened this issue Jul 5, 2021 · 15 comments · Fixed by #328
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

Comments

@yyt6200
Copy link

yyt6200 commented Jul 5, 2021

this branch name is '测试分支',click this branch,the ks is report error.

My running environment is as follows:

kubernets:1.9.10

kubesphere:3.1.0

image

@swiftslee
Copy link

/cc @kubesphere/sig-devops

@swiftslee
Copy link

/kind bug
/milestone v3.2

@JohnNiang
Copy link
Member

/area devops
/milestone v3.1

@LinuxSuRen
Copy link
Member

hi @yyt6200 thanks for reporting this issue to us.

@yyt6200
Copy link
Author

yyt6200 commented Jul 6, 2021

hi @yyt6200 thanks for reporting this issue to us.

you are welcome .

@LinuxSuRen
Copy link
Member

/milestone v3.2

@LinuxSuRen LinuxSuRen transferred this issue from kubesphere/kubesphere Aug 5, 2021
@LinuxSuRen LinuxSuRen added the hacktoberfest https://hacktoberfest.digitalocean.com/ label Oct 15, 2021
@LinuxSuRen
Copy link
Member

The is the log output from the backend.

│ devops-apiserver-5456ddd748-l6r4s I1015 07:42:44.592849       1 apiserver.go:295] 10.42.0.50 - "GET /v1alpha3/namespaces/testbfbp5/pipelines/multi-branch-g ││ it-footrapid/pipelineruns?page=1&limit=10&branch=%E6%B5%8B%E8%AF%95%E5%88%86%E6%94%AF&backward=false HTTP/1.1" 500 352 0ms                                  ││ devops-apiserver-5456ddd748-l6r4s E1015 07:42:48.576139       1 utils.go:76] /workspace/pkg/kapis/devops/v1alpha3/pipelinerun/handler.go:58 invalid label v ││ alue: "测试分支": at key: "devops.kubesphere.io/scm-ref-name": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.' ││ , and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0- ││ _.[]*)?[A-Za-z0-9])?')

Here are some clues. Please check it if you are interested to help us to fix it:

  • Make sure don't use any invalid characters when saving it
  • Use the same way to build the label selector to query target PipelineRuns
  • Please consider the naming rules of the git branch name and Kubernetes label value

/good-first-issue

@ks-ci-bot
Copy link
Collaborator

@LinuxSuRen:
This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.

In response to this:

The is the log output from the backend.

│ devops-apiserver-5456ddd748-l6r4s I1015 07:42:44.592849       1 apiserver.go:295] 10.42.0.50 - "GET /v1alpha3/namespaces/testbfbp5/pipelines/multi-branch-g ││ it-footrapid/pipelineruns?page=1&limit=10&branch=%E6%B5%8B%E8%AF%95%E5%88%86%E6%94%AF&backward=false HTTP/1.1" 500 352 0ms                                  ││ devops-apiserver-5456ddd748-l6r4s E1015 07:42:48.576139       1 utils.go:76] /workspace/pkg/kapis/devops/v1alpha3/pipelinerun/handler.go:58 invalid label v ││ alue: "测试分支": at key: "devops.kubesphere.io/scm-ref-name": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.' ││ , and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0- ││ _.[]*)?[A-Za-z0-9])?')

Here are some clues. Please check it if you are interested to help us to fix it:

  • Make sure don't use any invalid characters when saving it
  • Use the same way to build the label selector to query target PipelineRuns
  • Please consider the naming rules of the git branch name and Kubernetes label value

/good-first-issue

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ks-ci-bot ks-ci-bot added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Oct 15, 2021
@mangoGoForward
Copy link
Member

/assign

@LinuxSuRen
Copy link
Member

hi @mangoGoForward, good to see that you are interested in this issue. Please don't hesitate to contact us if you have any questions about this.

@mangoGoForward
Copy link
Member

hi @mangoGoForward, good to see that you are interested in this issue. Please don't hesitate to contact us if you have any questions about this.

OK, Thank you for your advice, I will try to solve this issue.

@mangoGoForward
Copy link
Member

The is the log output from the backend.

│ devops-apiserver-5456ddd748-l6r4s I1015 07:42:44.592849       1 apiserver.go:295] 10.42.0.50 - "GET /v1alpha3/namespaces/testbfbp5/pipelines/multi-branch-g ││ it-footrapid/pipelineruns?page=1&limit=10&branch=%E6%B5%8B%E8%AF%95%E5%88%86%E6%94%AF&backward=false HTTP/1.1" 500 352 0ms                                  ││ devops-apiserver-5456ddd748-l6r4s E1015 07:42:48.576139       1 utils.go:76] /workspace/pkg/kapis/devops/v1alpha3/pipelinerun/handler.go:58 invalid label v ││ alue: "测试分支": at key: "devops.kubesphere.io/scm-ref-name": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.' ││ , and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0- ││ _.[]*)?[A-Za-z0-9])?')

Here are some clues. Please check it if you are interested to help us to fix it:

  • Make sure don't use any invalid characters when saving it
  • Use the same way to build the label selector to query target PipelineRuns
  • Please consider the naming rules of the git branch name and Kubernetes label value

I have some questions, can you help me? @LinuxSuRen

  1. If refName is invalid(not match '(([A-Za-z0-9][-A-Za-z0- ││ _.[]*)?[A-Za-z0-9])?')), what should we do next
  2. What do you mean that Please consider the naming rules of the git branch name and Kubernetes label value

@LinuxSuRen
Copy link
Member

  1. I didn't have a perfect idea for now. But we might encode the invalid refName, and make it to be valid.
  2. I mean can try more string according to the rules of git branch name and k8s label value when you do the manual tests.

@mangoGoForward
Copy link
Member

  1. I didn't have a perfect idea for now. But we might encode the invalid refName, and make it to be valid.
  2. I mean can try more string according to the rules of git branch name and k8s label value when you do the manual tests.

How about randomly generate a valid string for the branch name when it is invalid, and add a label in Annotations to save the real git branch name, make a symbol in Labels

@JohnNiang
Copy link
Member

JohnNiang commented Oct 26, 2021

Hi @mangoGoForward , I have a better solution here for reference.

Because the branch name dose not always meet the naming requirements of label value, I don't recommend putting the branch name on the label.

if err := h.client.List(context.Background(), &prs,
client.InNamespace(pipeline.Namespace),
client.MatchingLabelsSelector{Selector: labelSelector}); err != nil {
api.HandleError(request, response, err)
return
}

When we query PipelineRuns, function client.Client#List in controller-manager has some useful ListOptionss, such as client.MatchingFields{"branch":"main"}.

But by default, Kubernetes only a few field selector are supported. So we need to create a custom indexer for branch name.

I will put critical code here:

  1. When APIServer is initializing:
		if err := o.cache.IndexField(context.Background(), &v1alpha3.PipelineRun{}, "scm_ref_name", func(o runtime.Object) []string {
			pipelineRun, ok := o.(*v1alpha3.PipelineRun)
			if !ok || pipelineRun.Spec.SCM == nil {
				return []string{""}
			}
			return []string{pipelineRun.Spec.SCM.RefName}
		}); err != nil {
			klog.Errorf("failed to create index field (branch) for PipelineRun, err = %v", err)
		}
  1. When we use the indexer
	if err := h.client.List(context.Background(), &prs,
		client.InNamespace(pipeline.Namespace),
		client.MatchingLabelsSelector{Selector: labelSelector},
		client.MatchingFields{
			"scm_ref_name": branchName,
		}); err != nil {
		api.HandleError(request, response, err)
		return
	}
  1. Finally, we should be noted that we need undo label set for branch name in PipelineRun reconciler:

if refName, err := getSCMRefName(&pipelineRunCopied.Spec); err == nil && refName != "" {
pipelineRunCopied.Labels[v1alpha3.SCMRefNameLabelKey] = refName
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants