Skip to content

Kubernetes Stdlib tests - #307

Merged
aluzzardi merged 4 commits into
dagger:mainfrom
TomChv:kubernetes-test
Apr 15, 2021
Merged

aluzzardi merged 4 commits into
dagger:mainfrom
TomChv:kubernetes-test

Conversation

@TomChv

@TomChv TomChv commented Apr 9, 2021 •

Copy link
Copy Markdown
Member

Setup

In order to reach local kubernetes cluster. I've added the flag --net=host on buildkit container.

Actually, buildkit has an isolation problem, when we use --net=host to run buildkit, it doesn't isolate commands anymore. This bug make this PR possible.

⚠️ To run the test in the CI, we must use the KinD Github Action

Kubernetes Fix

I also fixed the kubernetes library, there was a problem with source inline :

if sourceInline != _|_ {
  op.#WriteFile & {
    dest:    "/source"
    content: source // Must be sourceInline to work
  }
},

Tests

  • Create a simple pod through sourceInline
  • Deploy a basic helm chart

Helpers

I've also added a file named verify.cue to :

  • Verify that pods has been created
  • Clear (when it's possible) pods after verification

Comment thread pkg/buildkitd/buildkitd.go Resolved
Comment thread stdlib/kubernetes/kubernetes.cue Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @samalba

Comment thread tests/stdlib/kubernetes/helm/verify.cue Resolved
Comment thread tests/stdlib/kubernetes/helm/helm.cue Resolved
Comment thread tests/stdlib/kubernetes/helm/helm.cue Resolved
Comment thread tests/stdlib/kubernetes/helm/helm.cue Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to resolve this to finish all tests

Comment thread tests/test-stdlib.sh Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find a way to automatically skip those tests when kind is not available.

You can look at test::secret in test-lib.sh for an example on how we skip tests that require secrets automatically when secrets are not available.

@TomChv TomChv Apr 9, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a simple condition statement to handle it.

I check if a kubeconfig exist as ~/.kube/config file and then I check if the user in the kubeconfig is kind.
If the condition is true, we are 100% sure that our kubeconfig is used to read a kind cluster.

if [ -f "/home/$USER/.kube/config" ] && grep -q "kind" "/home/$USER/.kube/config" &> /dev/null; then
    # Do test
then
    # Skip message
fi

Is it okay ?

@TomChv

TomChv commented Apr 9, 2021

Copy link
Copy Markdown
Member Author

/cc @aluzzardi

I found a bug in the helm package.

It works well when I send a directory as chart.

But when I want to deploy a chart from repository, there is a problem.

Reproduce

Here is the cue config

	helm.#Chart & {
		name:        chartName
		"namespace": namespace
		kubeconfig:  config.contents
		chart:       "redis" // Doesn't work
	}

Output

INF | #18 12.69 "repository" has been added to your repositories
INF | #18 12.75 Hang tight while we grab the latest from your chart repositories...
INF | #18 25.26 ...Successfully got an update from the "repository" chart repository
INF | #18 25.26 Update Complete. ⎈Happy Helming!⎈
INF | #18 25.55 Error from server (AlreadyExists): namespaces "dagger-test" already exists
INF | #18 25.59 Release "dagger-test-helm-repository" does not exist. Installing it now.
INF | failed: [/bin/bash --noprofile --norc -eo pipefail /entrypoint.sh]: exit code: 1    duration=25.6s
INF| #18 25.59 Error: Chart.yaml file is missing

Research

I dig into helm package and found the origin of the problem and tried to print the HELM_CHART variable from code.cue. Here's the output.

ERR | #18 25.55 Error from server (AlreadyExists): namespaces "dagger-test" already exists
INF   | #18 25.55 Helm: /helm/chart # <------- It should be "repository/redis"
INF   | #18 25.59 Release "dagger-test-helm-repository" does not exist. Installing it now.
ERR | failed: [/bin/bash --noprofile --norc -eo pipefail /entrypoint.sh]: exit code: 1    duration=25.6s
ERR | #18 25.59 Error: Chart.yaml file is missing

The bug come from that piece of code

if [ -f "/helm/chart" ]; then
    HELM_CHART="repository/$(cat /helm/chart)"
else
    HELM_CHART="/helm/chart"
fi

The file /helm/chart come from

mount: {
	if (values & string) != _|_ {
		"/helm/values.yaml": values
	}
	if chartInline == _|_ {
		"/helm/chart": from: chart // <--- Here
	}
}

I just don't understand why "redis" doesn't work because it should be consider as a dagger.#Artifact and dagger doesn't throw any type error...

I can't finish TestHelmRepoChart until that bug isn't fix. ATM, I didn't find a fix...

@aluzzardi

Copy link
Copy Markdown
Contributor

/cc @samalba

I just don't understand why "redis" doesn't work because it should be consider as a dagger.#Artifact and dagger doesn't throw any type error...

No, redis is a string, not a dagger.#Artifact (an artifact is a directory).

I think it got broken while being ported from stackbrew.

Background: helm supports two kind of charts: either a directory (dagger.#Artifact) or a name from a repository (e.g. redis).

There's quite a few fixes to do here:

  • Spec: we should have two inputs, either we pass a directory or a chart name:
chartSource: dagger.#Artifact
chart: string
  • For an artifact (e.g. chartSource), we should mount it:
			mount: {
				if chartSource != _|_ {
					"/helm/chart": from: chartSource
				}
			}
  • For a string (e.g. chart), we should write a file:
		if chart != _|_ {
			op.#WriteFile & {
				dest:    "/helm/chart"
				content: chart
			}
		},
  • values.yamlshould be written as a file
				if (values & string) != _|_ {
                                   op.#WriteFile ...
				}

Comment thread tests/stdlib/kubernetes/helm/helm.cue Resolved
Comment thread tests/stdlib/kubernetes/kubernetes.cue Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved inside TestKubeApply and randomized to avoid conflicting between test runs.

See

for an example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also look at the structure of that test as a reference)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
But I got a cycle error in kubernetes.cue if I put the random in TestKubeApply so I put it outside to solve that problem

Comment thread tests/test-stdlib.sh Resolved
Comment thread tests/stdlib/kubernetes/helm/helm.cue Resolved

@aluzzardi aluzzardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good! A few last comments

Comment thread tests/stdlib/kubernetes/kubernetes.cue Resolved
Comment thread tests/stdlib/kubernetes/helm/helm.cue Resolved
TomChv added 4 commits April 15, 2021 12:37
tests(stdlib/kubernetes): add kubernetes basic Apply test

Signed-off-by: Tom Chauveau <[email protected]>
tests(stdlib/k8s/helm): add verification
style(tests/): rename helper into verify to confirm that deployments works

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv TomChv changed the title [WIP] Kubernetes Stdlib tests Kubernetes Stdlib tests Apr 15, 2021
@aluzzardi
aluzzardi merged commit 551f281 into dagger:main Apr 15, 2021
vito added a commit that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302) and tree-sitter compiled
to WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer
needs cgo anywhere, and its highlighter (dang.Highlight) is usable from
any binary.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to
WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs
cgo anywhere, and its highlighter (dang.Highlight) is usable from any
binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list
hints suggest `value.{{id}}`, and a failed declaration no longer cascades
"not found" errors through its uses.

Signed-off-by: Alex Suraci <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants