Skip to content

Commit a051e6f

Browse files
committed
fix(docs): use correct Kustomize Component apiVersion, close coverage gap
Address CodeRabbit full-review findings on #2874: - All Component examples/fixtures used kustomize.config.k8s.io/v1beta1, which is Kustomization's version, not Component's (v1alpha1). Since isKustomizeConfigObject matches exact (apiVersion, kind) pairs, the examples never actually got the metadata.name exemption they claimed. Fixed in the blog post, the kubernetes.mdx walkthrough, and test fixtures; kubernetes-validate.mdx now documents both exact pairs instead of a kustomize.config.k8s.io/* wildcard. - Added TestWriteArtifactSingleFileModeWriteFailure, closing the patch coverage gap Codecov flagged on writeSingleArtifactFile's two new error branches (MkdirAll/WriteFile failure), mirroring the existing split=true failure test.
1 parent 9ae0b31 commit a051e6f

4 files changed

Lines changed: 42 additions & 13 deletions

File tree

pkg/provisioner/target/git/git_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestWriteArtifactSingleFileMode(t *testing.T) {
248248
path := filepath.Join("kustomize", "overlays", "prod", "kustomization.yaml")
249249

250250
artifact := &target.ProvisionArtifact{Files: map[string][]byte{
251-
"001_kustomize.config.k8s.io_v1beta1_Component_cert-manager.yaml": []byte("apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Component\n"),
251+
"001_kustomize.config.k8s.io_v1alpha1_Component_cert-manager.yaml": []byte("apiVersion: kustomize.config.k8s.io/v1alpha1\nkind: Component\n"),
252252
}}
253253
require.NoError(t, writeArtifact(workdir, path, artifact, false))
254254

@@ -259,7 +259,7 @@ func TestWriteArtifactSingleFileMode(t *testing.T) {
259259

260260
got, err := os.ReadFile(abs)
261261
require.NoError(t, err)
262-
assert.Equal(t, "apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Component\n", string(got))
262+
assert.Equal(t, "apiVersion: kustomize.config.k8s.io/v1alpha1\nkind: Component\n", string(got))
263263
}
264264

265265
func TestWriteArtifactSingleFileModeMergesMultipleDocuments(t *testing.T) {
@@ -287,7 +287,7 @@ func TestWriteArtifactSingleFileModeReplacesExistingDirectory(t *testing.T) {
287287
require.NoError(t, os.MkdirAll(filepath.Join(stale, "001_stale.yaml"), 0o755))
288288

289289
artifact := &target.ProvisionArtifact{Files: map[string][]byte{
290-
"001_kustomize.config.k8s.io_v1beta1_Component.yaml": []byte("kind: Component\n"),
290+
"001_kustomize.config.k8s.io_v1alpha1_Component.yaml": []byte("kind: Component\n"),
291291
}}
292292
require.NoError(t, writeArtifact(workdir, path, artifact, false))
293293

@@ -320,6 +320,30 @@ func TestWriteArtifactWriteFailure(t *testing.T) {
320320
assert.ErrorIs(t, err, errUtils.ErrGitArtifactWrite)
321321
}
322322

323+
func TestWriteArtifactSingleFileModeWriteFailure(t *testing.T) {
324+
if runtime.GOOS == "windows" {
325+
t.Skip("file-mode permissions behave differently on Windows")
326+
}
327+
if currentUser, userErr := user.Current(); userErr == nil && (currentUser.Uid == "0" || currentUser.Username == "root") {
328+
t.Skip("running as root ignores filesystem permissions")
329+
}
330+
331+
workdir := t.TempDir()
332+
// Make a read-only managed-path parent so writeSingleArtifactFile's
333+
// MkdirAll/WriteFile under it fail.
334+
managed := filepath.Join(workdir, "clusters")
335+
require.NoError(t, os.Mkdir(managed, 0o555))
336+
t.Cleanup(func() {
337+
_ = os.Chmod(managed, 0o755)
338+
})
339+
340+
err := writeArtifact(workdir, filepath.Join("clusters", "dev", "manifest.yaml"), &target.ProvisionArtifact{Files: map[string][]byte{
341+
"namespace.yaml": []byte("kind: Namespace\n"),
342+
}}, false)
343+
require.Error(t, err)
344+
assert.ErrorIs(t, err, errUtils.ErrGitArtifactWrite)
345+
}
346+
323347
func TestDeliverProviderNotFound(t *testing.T) {
324348
g := &gitProvisioner{}
325349
atmosConfig := &schema.AtmosConfiguration{

website/blog/2026-08-05-kustomize-gitops-delivery.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ components:
5454
commit:
5555
message: "Render manifests for {{ .vars.environment }}"
5656
manifests:
57-
- apiVersion: kustomize.config.k8s.io/v1beta1
57+
- apiVersion: kustomize.config.k8s.io/v1alpha1
5858
kind: Component
5959
patches:
6060
- target:

website/docs/cli/commands/kubernetes/kubernetes-validate.mdx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ With `--server`:
103103

104104
### Kustomize config objects
105105

106-
Kustomize's own `Kustomization` and `Component` objects
107-
(`apiVersion: kustomize.config.k8s.io/*`) are not Kubernetes API resources —
108-
they are local input consumed by the `kustomize` build tool itself, and
109-
Kustomize does not require (or, historically, even permit) a `metadata.name`
110-
on them. `validate` recognizes these two kinds specifically and does not
111-
require `metadata.name` for them; every other offline check (a resolvable
112-
group/version/kind, and DNS-1123 validity for a name that *is* given) still
113-
applies. See
106+
Kustomize's own `Kustomization` and `Component` objects are not Kubernetes API
107+
resources — they are local input consumed by the `kustomize` build tool
108+
itself, and Kustomize does not require (or, historically, even permit) a
109+
`metadata.name` on them. `validate` recognizes these two exact, versioned
110+
pairs and does not require `metadata.name` for them:
111+
112+
- `apiVersion: kustomize.config.k8s.io/v1beta1`, `kind: Kustomization`
113+
- `apiVersion: kustomize.config.k8s.io/v1alpha1`, `kind: Component`
114+
115+
A `Kustomization`/`Component` object at a different `apiVersion` is not
116+
recognized and still requires `metadata.name`. Every other offline check (a
117+
resolvable group/version/kind, and DNS-1123 validity for a name that *is*
118+
given) still applies regardless. See
114119
[Generating a Kustomize component for GitOps](/stacks/components/kubernetes#generating-a-kustomize-component-for-gitops)
115120
for the pattern this supports.
116121

website/docs/stacks/components/kubernetes.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ components:
267267
commit:
268268
message: "Render manifests for {{ .vars.environment }}"
269269
manifests:
270-
- apiVersion: kustomize.config.k8s.io/v1beta1
270+
- apiVersion: kustomize.config.k8s.io/v1alpha1
271271
kind: Component
272272
patches:
273273
- target:

0 commit comments

Comments
 (0)