Comments (10)
Could you share a code example and the command you ran?
from kubenix.
Here is a code example (imported as a module):
{
kubernetes.resources.namespaces.test-namespace = { };
kubernetes.resources.pods.example = {
metadata.namespace = "test-namespace";
spec.containers.nginx.image = "nginx";
};
}
Running this gives the error (:
$ nix run .#kubenix.x86_64-linux
Error from server (NotFound): namespaces "test-namespace" not found
Doing something like this in YAML does work though:
apiVersion: v1
kind: Namespace
metadata:
name: test-namespace
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: test-namespace
spec:
containers:
- name: nginx
image: nginx
$ kubectl apply -f ./repro.yaml
namespace/test-namespace created
pod/nginx created
Maybe this is caused by the diff
s?
from kubenix.
Ah wait, changing the order in the YAML file does matter. If I put the pod definition before the namespace definition, you get the same error.
from kubenix.
Changing the kubernetes.resourceOrder
option to the following also doesn't fix this issue:
kubernetes.resourceOrder = [
"Namespace"
"Pod"
];
from kubenix.
Default order should already put the namespace first, so maybe something messes up with the ordering on the way from nix to final yaml?
Line 328 in 76b8053
from kubenix.
Could you run nix eval —json
on generated to see if the order is right? If it’s not then it’s something wrong with ordering logic
from kubenix.
How do I do that exactly? I'm using Kubenix as a flake output with outputs.kubenix = kubenix.packages.${system}.default .override {}
.
from kubenix.
ok, so if you run:
nix build .#kubenix
you can then inspect the generated manifest with:
jq . result/manifest.json
which should show something like:
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubenix/k8s-version": "1.27",
"kubenix/project-name": "kubenix"
},
"labels": {
"kubenix/hash": "dc73d66262ab324ab024e6f3258fff7ad526113b"
},
"name": "test-namespace"
}
},
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"annotations": {
"kubenix/k8s-version": "1.27",
"kubenix/project-name": "kubenix"
},
"labels": {
"kubenix/hash": "dc73d66262ab324ab024e6f3258fff7ad526113b"
},
"name": "example",
"namespace": "test-namespace"
},
"spec": {
"containers": [
{
"image": "nginx",
"name": "nginx"
}
]
}
}
],
"kind": "List",
"labels": {
"kubenix/hash": "dc73d66262ab324ab024e6f3258fff7ad526113b",
"kubenix/k8s-version": "1.27",
"kubenix/project-name": "kubenix"
}
}
with Namespace first in the array
this works for me:
kubectl apply -f result/manifest.json
with output:
namespace/test-namespace created
pod/example created
but I got the same error as you when running:
kubectl apply --dry-run=server -f result/manifest.json
the error you are getting is from the diff
part of the script, see:
nix run .#kubenix diff
from kubenix.
This is actually the same problem @hall talked about here: #23 (comment)
And to quote upstream Kubectl:
Yeah, this is hard, I have no clue how we can fix this properly, not without very complicated machinery.
from kubenix.
Looked at Kapp as an alternative to plain kubectl. Kapp only really works when you use their kapp.k14s.io
labels, which seems unreasonable to ask of users of Kubenix in my opinion. I think I will use this for my home lab though, as it is quite convenient :)
So yeah, I don't think we should/can fix this in kubectl.
from kubenix.
Related Issues (20)
- Example Deployment in docs does not work HOT 2
- document some deployment options
- Trouble with custom resources within helm charts HOT 5
- Remove assumption that custom resources have a spec field HOT 1
- Validate custom resources without having to manually define modules for them HOT 3
- Provide namespaced module by default HOT 1
- Search box in docs not working HOT 1
- ConfigMap data keys with leading underscore get removed
- kubeconfig: unbound variable HOT 5
- Deprecated: kubectl apply will no longer prune non-namespaced resources by default HOT 1
- Unable to remove the last defined resource with bulit-in deploy tool
- Generated kubernetes module requires `protocol` in `Container.ports` which is not required by spec HOT 2
- Helm `lookup`s are not executed HOT 2
- error: undefined variable 'system' when trying to initialise example with nix v2.21.0
- kubenix script has no shebang, leading to "Exec format error" HOT 2
- Vals errors should abort kubectl apply
- `nix run .#kubenix`, `error: cannot coerce null to a string` HOT 1
- vals cannot read secrets from sops when using gpg
- Default namespace is incorrectly applied to clusterwide resources HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kubenix.