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

on apply error, from kubectl edit, we should indicate the suspect line number #4795

Closed
starpit opened this issue Jun 1, 2020 · 2 comments · Fixed by #4843
Closed

on apply error, from kubectl edit, we should indicate the suspect line number #4795

starpit opened this issue Jun 1, 2020 · 2 comments · Fixed by #4843
Labels
kind/feature Categorizes issue or PR as related to a new feature. plugin-kubectl

Comments

@starpit
Copy link
Contributor

starpit commented Jun 1, 2020

this will require parsing out the low-level kubectl message. e.g. in the following error, the line prefixed with "-" is the one we would like to mark in monaco-editor. we could use monaco's line markers to do so.

Error: The Pod "kui-two-containers" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)
  core.PodSpec{
  	Volumes:        []core.Volume{{Name: "default-token-7w5df", VolumeSource: core.VolumeSource{Secret: &core.SecretVolumeSource{SecretName: "default-token-7w5df", DefaultMode: &420}}}},
  	InitContainers: nil,
  	Containers: []core.Container{
  		{
  			Name:  "a",
  			Image: "jare/alpine-vim",
  			Command: []string{
  				"/bin/sh",
  				"-c",
- 				"while true; do echo a; sleep 2; done",
+ 				"while true; do echo a; sleep 1; done",
  			},
  			Args:       nil,
  			WorkingDir: "",
  			... // 16 identical fields
  		},
  		{Name: "b", Image: "jare/alpine-vim", Command: []string{"/bin/sh", "-c", "while true; do echo b; sleep 1; done"}, VolumeMounts: []core.VolumeMount{{Name: "default-token-7w5df", ReadOnly: true, MountPath: "/var/run/secrets/kubernetes.io/serviceaccount"}}, TerminationMessagePath: "/dev/termination-log", TerminationMessagePolicy: "File", ImagePullPolicy: "Always"},
  	},
  	RestartPolicy:                 "Always",
  	TerminationGracePeriodSeconds: &30,
  	... // 21 identical fields
  }
@starpit
Copy link
Contributor Author

starpit commented Jun 1, 2020

a candidate algorithm, if errMsg is the above example, as a string, and yaml is the source, as as a string:

  1. const s = yaml.split(/\n/)
  2. const m = errMsg.split(/\n/)
  3. const x = x = m[m.findIndex(_ => /^-\s/.test(_))].replace(/^-\s/, '').trim().replace(/^"(.*)",?$/, '$1')
  4. const idx = s.findIndex(_ => _.indexOf(x) >= 0)

x is the important part of the line of the error message that indicates the failure, and idx is the line index of s that contains that x

x is the ugly part, because of the way kubectl encodes things. we have to unwrap the leading “-”, then remove whatever whitespace it might add (because kubectl’s whitespace is not the same as in the original s), then kubectl adds quotation marks, and possibly a trailing comma

@starpit starpit added kind/feature Categorizes issue or PR as related to a new feature. plugin-kubectl labels Jun 4, 2020
@starpit
Copy link
Contributor Author

starpit commented Jun 5, 2020

we may also want to link to the line numbers in the error alert. i.e. in a way that causes the monaco editor to scroll that line into view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. plugin-kubectl
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant