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

doc/tutorial/kubernetes: tidy up and move to github.com/cue-examples #824

Closed
cueckoo opened this issue Jul 3, 2021 · 7 comments
Closed
Labels
Documentation get go issues related to cue get go NeedsFix

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @myitcv in cuelang/cue#824

Here are the remaining TODOs following a recent review of the Kubernetes tutorial as part of https://cue-review.googlesource.com/c/cue/+/8961:

  • the output from commands has gone a bit stale
  • we have larger diffs than expected in some situations
  • we are not asserting the success of each step, which means that steps can fail and it go unnoticed
  • we are not re-running the tutorial as part of CI
  • we are not running the entire tutorial, we skip certain commands
  • the tests in doc/tutorial/kubernetes pass even when critical files are missing (again because we ignore the exit code of all commands we run)

The tutorial still "works" it's just that a user following along might well, understandably, be thrown by discrepancies.

Fundamentally we need to fix the scenario where today, running CUE_UPDATE=1 go test ./... using Go 1.16 breaks by removing a series of files in doc/tutorial/kubernetes/quick/**/*.cue.

Ideally we fix this by making the tutorial a guide that is re-run with an appropriate Docker image using preguide. That however raises the question of whether the tutorial should continue to live as part of the main repo:

  • re-running the guide each time will take some time
  • however the guide is a good source of potential issues and so any diffs that result from a change in CUE are potentially of significance/interest and so catching these as early as possible would be best

We could/should use something like https://github.com/thetirefire/badidea for a minimal Kubernetes setup so that the guide can run kubectl

2022-05-19 update: progress being made over in https://github.com/cue-examples/kubernetes-tutorial.

@cueckoo cueckoo added Documentation get go issues related to cue get go NeedsFix labels Jul 3, 2021
@cueckoo cueckoo added this to the v0.4.x milestone Jul 3, 2021
@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @pfiaux in cuelang/cue#824 (comment)

Hey, I'm not sure if this is the right place to post but I recently completed the tutorial (this weekend) and ran into a few issues. Let me know if I should create a separate issue instead.

There are the ones I remember, I looked at a few commits above and didn't see them sorry if I missed them.

The dump command uses --dry-run which spits out warning, changing it to --dry-run=client worked for me (kubectl 1.19).

After generating definitions from the go code and adding k8s_defs.cue I couldn't dump anymore (i.e. cue cmd dump ./frontend/maitred) I was getting something like this:

service.maitred.spec.ports.0.targetPort: conflicting values close(#IntOrString) and (*7080 | int) (mismatched types struct and int):
../cue.mod/gen/k8s.io/api/core/v1/types_go_gen.cue:4769:15
../cue.mod/gen/k8s.io/apimachinery/pkg/util/intstr/intstr_go_gen.cue:16:15
./kube.cue:83:16
From what I could see port is defined as int32 and targetPort int or string or fallback to port, the following changes to kube.cue worked for me:

import "k8s.io/apimachinery/pkg/util/intstr"
// ... rest of the code here
 				// Replacing the port definitions:
				port:       *Port | int32
				targetPort?: *Port | intstr.#IntOrString

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @myitcv in cuelang/cue#824 (comment)

Thanks @pfiaux. One of the challenges with the tutorial is that we do not, currently, faithfully execute each command as the user would. This issue is precisely about fixing it so that we do, in order that we don't run into problems of the sort you have reported.

One way of achieving that would be to re-run the tutorial within a docker container that has kubectl available. If you or anyone else has advice on a minimal Docker image that would allow us to do that, it would be greatly appreciated.

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @pfiaux in cuelang/cue#824 (comment)

From what I remember with dry run you don't actually need much from the cluster itself, just a connection (I think at the time I ran it against an empty minikube cluster i had locally). I've had some luck getting k3s/k3d (https://github.com/rancher/k3d) running locally, I haven't tried in a pipeline tho.

I'm not familiar with github actions would https://github.com/AbsaOSS/k3d-action be a possible solution?

There's also https://kind.sigs.k8s.io/ but image looks bigger and I have no idea how easy it is.

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @myitcv in cuelang/cue#824 (comment)

I've had some luck getting k3s/k3d (https://github.com/rancher/k3d) running locally, I haven't tried in a pipeline tho.

Thanks, this is useful. I just managed to get k3d working, to then call kubectl against it (all we need to do is invoke kubectl --dry-fun). So in theory, this will work as part of a preguide guide.

I'm not familiar with github actions would https://github.com/AbsaOSS/k3d-action be a possible solution?

I'm sure something like that works, yes, but we need something that will work client side here, in case changes need to be made to the tutorial. The k3d approach you suggested (or even minikube) sounds like it's the best way forwards.

Appreciate your suggestions!

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @myitcv in cuelang/cue#824 (comment)

Whilst waiting at the dentist (random, I realise) I made a bit more progress on this using k3d.

The Docker image I am using is defined here:

https://github.com/play-with-go/docker/tree/cue-kubernetes-tutorial/cue-kubernetes-tutorial

A partially converted guide can be found here:

https://github.com/play-with-go/play-with-go/blob/cue-kubernetes-tutorial/guides/2021-03-10-cue-kubernetes-tutorial/guide.cue

As an aide memoire, that guide can be regenerated via:

go run github.com/play-with-go/preguide/cmd/preguide gen -runargs 'term1=-v cue-kubernetes-tutorial:/var --privileged -e GOMODCACHE=/var/gomodcache -e GOCACHE=/var/gocache' -run kubernetes -out ../_posts

Proof that this setup works with kubectl can be found in the log:

https://github.com/play-with-go/play-with-go/blob/cue-kubernetes-tutorial/guides/2021-03-10-cue-kubernetes-tutorial/go115_en_log.txt

myitcv added a commit that referenced this issue Feb 19, 2022
Over time the Kubernetes tutorial has gone a bit stale:

* the output from commands has gone stale;
* we have larger diffs than expected in some situations;
* we are not asserting the success of each step, which means that steps
  can fail and it go unnoticed;
* we are not re-running the tutorial as part of CI;
* we are not running the entire tutorial, we skip certain commands;
* the tests in doc/tutorial/kubernetes pass even when critical files are
  missing (again because we ignore the exit code of all commands we
  run).

The ultimate fix is to migrate to a living tutorial at:

    https://github.com/cue-examples/kubernetes-tutorial

(which follows the same pattern as our FOSDEM 2022 talk).

For now, this CL patches things up to reduce the diffs between what the
end user sees in real life and the guide. Changes include:

* reordering of original YAML inputs so that the first
  the first trim (effectively a key part of the )

For #824

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie965fd24d710da69b18f0108e5415e6321859f8d
myitcv added a commit that referenced this issue Feb 21, 2022
Over time the Kubernetes tutorial has gone a bit stale:

* the output from commands has gone stale;
* we have larger diffs than expected in some situations;
* we are not asserting the success of each step, which means that steps
  can fail and it go unnoticed;
* we are not re-running the tutorial as part of CI;
* we are not running the entire tutorial, we skip certain commands;
* the tests in doc/tutorial/kubernetes pass even when critical files are
  missing (again because we ignore the exit code of all commands we
  run).

The ultimate fix is to migrate to a living tutorial at:

    https://github.com/cue-examples/kubernetes-tutorial

(which follows the same pattern as our FOSDEM 2022 talk).

For now, this CL patches things up to reduce the diffs between what the
end user sees in real life and the guide. Changes include the following.

Reordering of original YAML inputs so that the first the first trim
shows zero diff output. This is a hack for now but important because cue
trim being lossless is a key part of the demo. cue diff (or some variant
of that command) will obviate the need for fixing the order like this.

Fixing kubectl --dry-run flag to match the current standard.

Updating the number of lines in the output of wc post-cue trim.

Add a couple of missing re-baselines of snapshot.

Fix various typos.

Consistently use `wc -l` and `diff -wu` for readability purposes.

Format all CUE code consistently with cue fmt.

Use a stable version of k8s.io/api/apps/v1@v0.23.4 for the cue get go
step.

For #824

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie965fd24d710da69b18f0108e5415e6321859f8d
cueckoo pushed a commit that referenced this issue Feb 21, 2022
Over time the Kubernetes tutorial has gone a bit stale:

* the output from commands has gone stale;
* we have larger diffs than expected in some situations;
* we are not asserting the success of each step, which means that steps
  can fail and it go unnoticed;
* we are not re-running the tutorial as part of CI;
* we are not running the entire tutorial, we skip certain commands;
* the tests in doc/tutorial/kubernetes pass even when critical files are
  missing (again because we ignore the exit code of all commands we
  run).

The ultimate fix is to migrate to a living tutorial at:

    https://github.com/cue-examples/kubernetes-tutorial

(which follows the same pattern as our FOSDEM 2022 talk).

For now, this CL patches things up to reduce the diffs between what the
end user sees in real life and the guide. Changes include the following.

Reordering of original YAML inputs so that the first the first trim
shows zero diff output. This is a hack for now but important because cue
trim being lossless is a key part of the demo. cue diff (or some variant
of that command) will obviate the need for fixing the order like this.

Fixing kubectl --dry-run flag to match the current standard.

Updating the number of lines in the output of wc post-cue trim.

Add a couple of missing re-baselines of snapshot.

Fix various typos.

Consistently use `wc -l` and `diff -wu` for readability purposes.

Format all CUE code consistently with cue fmt.

Use a stable version of k8s.io/api/apps/v1@v0.23.4 for the cue get go
step.

For #824

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie965fd24d710da69b18f0108e5415e6321859f8d
cueckoo pushed a commit that referenced this issue Feb 22, 2022
Over time the Kubernetes tutorial has gone a bit stale:

* the output from commands has gone stale;
* we have larger diffs than expected in some situations;
* we are not asserting the success of each step, which means that steps
  can fail and it go unnoticed;
* we are not re-running the tutorial as part of CI;
* we are not running the entire tutorial, we skip certain commands;
* the tests in doc/tutorial/kubernetes pass even when critical files are
  missing (again because we ignore the exit code of all commands we
  run).

The ultimate fix is to migrate to a living tutorial at:

    https://github.com/cue-examples/kubernetes-tutorial

(which follows the same pattern as our FOSDEM 2022 talk).

For now, this CL patches things up to reduce the diffs between what the
end user sees in real life and the guide. Changes include the following.

Reordering of original YAML inputs so that the first the first trim
shows zero diff output. This is a hack for now but important because cue
trim being lossless is a key part of the demo. cue diff (or some variant
of that command) will obviate the need for fixing the order like this.

Fixing kubectl --dry-run flag to match the current standard.

Updating the number of lines in the output of wc post-cue trim.

Add a couple of missing re-baselines of snapshot.

Fix various typos.

Consistently use `wc -l` and `diff -wu` for readability purposes.

Format all CUE code consistently with cue fmt.

Use a stable version of k8s.io/api/apps/v1@v0.23.4 for the cue get go
step.

For #824

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie965fd24d710da69b18f0108e5415e6321859f8d
cueckoo pushed a commit that referenced this issue Feb 25, 2022
Over time the Kubernetes tutorial has gone a bit stale:

* the output from commands has gone stale;
* we have larger diffs than expected in some situations;
* we are not asserting the success of each step, which means that steps
  can fail and it go unnoticed;
* we are not re-running the tutorial as part of CI;
* we are not running the entire tutorial, we skip certain commands;
* the tests in doc/tutorial/kubernetes pass even when critical files are
  missing (again because we ignore the exit code of all commands we
  run).

The ultimate fix is to migrate to a living tutorial at:

    https://github.com/cue-examples/kubernetes-tutorial

(which follows the same pattern as our FOSDEM 2022 talk).

For now, this CL patches things up to reduce the diffs between what the
end user sees in real life and the guide. Changes include the following.

Reordering of original YAML inputs so that the first the first trim
shows zero diff output. This is a hack for now but important because cue
trim being lossless is a key part of the demo. cue diff (or some variant
of that command) will obviate the need for fixing the order like this.

Fixing kubectl --dry-run flag to match the current standard.

Updating the number of lines in the output of wc post-cue trim.

Add a couple of missing re-baselines of snapshot.

Fix various typos.

Consistently use `wc -l` and `diff -wu` for readability purposes.

Format all CUE code consistently with cue fmt.

Use a stable version of k8s.io/api/apps/v1@v0.23.4 for the cue get go
step.

For #824

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie965fd24d710da69b18f0108e5415e6321859f8d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533453
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
@myitcv myitcv changed the title doc/tutorial/kubernetes: tidy up the tutorial doc/tutorial/kubernetes: tidy up and move to github.com/cue-examples May 19, 2022
@myitcv
Copy link
Member

myitcv commented May 19, 2022

Update: I've retitled this to better reflect the goal to move the Kubernetes tutorial outside of the main repo. A WIP translation to a preguide version can be found at https://github.com/cue-examples/kubernetes-tutorial

@myitcv myitcv removed this from the v0.4.x milestone Apr 27, 2023
@myitcv myitcv added the zGarden label Jun 15, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
@mvdan
Copy link
Member

mvdan commented May 16, 2024

@mvdan mvdan closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation get go issues related to cue get go NeedsFix
Projects
None yet
Development

No branches or pull requests

3 participants