Skip to content

Commit a296687

Browse files
committed
Add ansible scaffolding capability
Signed-off-by: chiragkyal <ckyal@redhat.com>
1 parent 87d6d1f commit a296687

File tree

2 files changed

+71
-0
lines changed
  • cmd/ansible-operator
  • internal/cmd/ansible-operator/scaffold

2 files changed

+71
-0
lines changed

cmd/ansible-operator/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
_ "k8s.io/client-go/plugin/pkg/client/auth"
2222

2323
"github.com/operator-framework/ansible-operator-plugins/internal/cmd/ansible-operator/run"
24+
"github.com/operator-framework/ansible-operator-plugins/internal/cmd/ansible-operator/scaffold"
2425
"github.com/operator-framework/ansible-operator-plugins/internal/cmd/ansible-operator/version"
2526
)
2627

@@ -36,6 +37,7 @@ operator project's image entrypoint
3637

3738
root.AddCommand(run.NewCmd())
3839
root.AddCommand(version.NewCmd())
40+
root.AddCommand(scaffold.NewCmd())
3941

4042
if err := root.Execute(); err != nil {
4143
log.Fatal(err)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package scaffold
16+
17+
import (
18+
"fmt"
19+
"log"
20+
"runtime"
21+
22+
"github.com/operator-framework/ansible-operator-plugins/pkg/plugins/ansible/v1"
23+
"github.com/spf13/cobra"
24+
25+
ver "github.com/operator-framework/ansible-operator-plugins/internal/version"
26+
"sigs.k8s.io/kubebuilder/v4/pkg/cli"
27+
cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3"
28+
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
29+
kustomizev2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2"
30+
)
31+
32+
func NewCmd() *cobra.Command {
33+
cli := GetPluginsCLI()
34+
return cli.Command()
35+
}
36+
37+
func GetPluginsCLI() *cli.CLI {
38+
ansibleBundle, _ := plugin.NewBundleWithOptions(
39+
plugin.WithName(ansible.Plugin{}.Name()),
40+
plugin.WithVersion(ansible.Plugin{}.Version()),
41+
plugin.WithPlugins(
42+
kustomizev2.Plugin{},
43+
ansible.Plugin{},
44+
),
45+
)
46+
47+
c, err := cli.New(
48+
cli.WithCommandName("scaffold"),
49+
cli.WithDescription("scaffolds ansible-operator"),
50+
cli.WithVersion(makeVersionString()),
51+
cli.WithPlugins(
52+
ansibleBundle,
53+
),
54+
cli.WithDefaultPlugins(cfgv3.Version, ansibleBundle),
55+
cli.WithDefaultProjectVersion(cfgv3.Version),
56+
cli.WithCompletion(),
57+
)
58+
59+
if err != nil {
60+
log.Fatal(err)
61+
}
62+
63+
return c
64+
}
65+
66+
func makeVersionString() string {
67+
return fmt.Sprintf("scaffold version: %q, commit: %q, kubernetes version: %q, go version: %q, GOOS: %q, GOARCH: %q",
68+
ver.GitVersion, ver.GitCommit, ver.KubernetesVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH)
69+
}

0 commit comments

Comments
 (0)