Skip to content

Inconsistent sample file naming in Ansible operator scaffolding (v1.36+) #7073

@rascasoft

Description

@rascasoft

Bug Report

What did you do?

Created a new Ansible-based operator using Operator SDK:

$ operator-sdk init --domain myorg.io --plugins ansible

Created a new API for kind "MyKind":

$ operator-sdk create api --version v1alpha1 --kind MyKind --generate-role

Examined the generated files in config/samples/:

$ ls -1 config/samples/
_v1alpha1_akit.yaml
kustomization.yaml

$ cat config/samples/kustomization.yaml
## Append samples of your project ##
resources:
- v1alpha1_mykind.yaml
- _v1alpha1_mykind.yaml
#+kubebuilder:scaffold:manifestskustomizesamples

The Ansible plugin scaffolding incorrectly adds both the underscored and non-underscored references

What did you expect to see?

I expected a single sample Custom Resource file to be created with consistent naming, and kustomization.yaml to reference only that one file.

Expected output:

Either v1alpha1_mykind.yaml or _v1alpha1_mykind.yaml (not both) and kustomization.yaml containing a single reference to the existing file:

## Append samples of your project ##
resources:
- v1alpha1_akit.yaml   # or _v1alpha1_akit.yaml depending on convention
# +kubebuilder:scaffold:manifestskustomizesamples

What did you see instead? Under which circumstances?

I observed inconsistent scaffolding: the actual file created was v1alpha1_mykind.yaml (without underscore) and kustomization.yaml contained both entries:

## Append samples of your project ##
resources:
- v1alpha1_mykind.yaml
- _v1alpha1_mykind.yaml
# +kubebuilder:scaffold:manifestskustomizesamples

The file _v1alpha1_mykind.yaml does not exist, causing make bundle to fail with:

Error: accumulating resources: accumulation err='accumulating resources from '../samples': '/home/myuser/myoperator/config/samples' must resolve to a file': recursed accumulation of path '/home/myuser/myoperator/config/samples': accumulating resources: accumulation err='accumulating resources from '_v1alpha1_mykind.yaml': evalsymlink failure on '/home/myuser/myoperator/config/samples/_v1alpha1_mykind.yaml' : lstat /home/myuser/myoperator/config/samples/_v1alpha1_mykind.yaml: no such file or directory': must build at directory: not a valid directory: evalsymlink failure on '/home/myuser/myoperator/config/samples/_v1alpha1_mykind.yaml' : lstat /home/myuser/myoperator/config/samples/_v1alpha1_mykind.yaml: no such file or directory

Additional testing: I tested various versions and found that this issue started with operator-sdk v1.36. Versions prior to 1.36 (e.g., 1.35) correctly generated a single consistent entry.

Environment

Operator type:

/language ansible

Kubernetes cluster type:

$ operator-sdk version

operator-sdk version: "v1.42.0", commit: "ab5563df5499cafa4ea9d40d4b36b51899a4718e", kubernetes version: "1.33.1", go version: "go1.24.6", GOOS: "linux", GOARCH: "amd64"

$ kubectl version

Client Version: v1.30.4
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.14

Possible Solution

The create api command should generate consistent file naming and kustomization references. Two possible fixes:

  • Option A: Generate the sample file with underscore (_v1alpha1_mykind.yaml) to match the existing kustomization template.
  • Option B: Generate the sample file without underscore and update kustomization.yaml to reference only that file.

Currently, the behavior is mixed: the file is created without underscore but kustomization references both, causing build failures.

Additional context

The issue appears to be specific to the Ansible plugin. The bug likely originated from a change in the scaffolding templates between v1.35 and v1.36 that caused both naming conventions to be written simultaneously.

Metadata

Metadata

Assignees

No one assigned

    Labels

    language/ansibleIssue is related to an Ansible operator project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions