diff --git a/.github/workflows/test-ansible.yml b/.github/workflows/test-ansible.yml index cecbe41..6efa964 100644 --- a/.github/workflows/test-ansible.yml +++ b/.github/workflows/test-ansible.yml @@ -36,3 +36,17 @@ jobs: pip3 install --user --upgrade setuptools pip pip3 install --user ansible-core~=2.17.4 make test-e2e-ansible-molecule + build-bin: + name: build-bin + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - name: Run make build + run: make build diff --git a/.gitignore b/.gitignore index f9f00bb..e3ce4fe 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /dist **/bin/ ansible-operator +ansible-cli # Test artifacts **/testbin/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 8b5dc5d..e75355e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -3,7 +3,7 @@ before: - go mod tidy - go mod download builds: - - id: binary + - id: ansible-operator main: ./cmd/ansible-operator/ binary: ansible-operator asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}" @@ -17,6 +17,20 @@ builds: - arm64 - ppc64le - s390x + - id: ansible-cli + main: ./cmd/ansible-cli/ + binary: ansible-cli + asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}" + gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}" + ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}" + mod_timestamp: "{{ .CommitTimestamp }}" + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x dockers: - image_templates: - "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64" diff --git a/Makefile b/Makefile index 0d88a48..2cefc9b 100644 --- a/Makefile +++ b/Makefile @@ -71,16 +71,16 @@ clean: ## Cleanup build artifacts and tool binaries. ##@ Build .PHONY: install -install: ## Install ansible-operator - GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go install $(GO_BUILD_ARGS) ./cmd/ansible-operator +install: ## Install ansible-operator and ansible-cli. + GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go install $(GO_BUILD_ARGS) ./cmd/{ansible-operator,ansible-cli} .PHONY: build -build: ## Build ansible-operator +build: ## Build ansible-operator and ansible-cli. @mkdir -p $(BUILD_DIR) - GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./cmd/ansible-operator + GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./cmd/{ansible-operator,ansible-cli} -.PHONY: build/ansible-operator -build/ansible-operator: +.PHONY: build/ansible-operator build/ansible-cli +build/ansible-operator build/ansible-cli: GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go build $(GO_BUILD_ARGS) -o $(BUILD_DIR)/$(@F) ./cmd/$(@F) ##@ Dev image build diff --git a/cmd/ansible-cli/main.go b/cmd/ansible-cli/main.go new file mode 100644 index 0000000..b166f3c --- /dev/null +++ b/cmd/ansible-cli/main.go @@ -0,0 +1,28 @@ +// Copyright 2025 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "log" + + "github.com/operator-framework/ansible-operator-plugins/internal/cmd/ansible-cli/cli" + _ "k8s.io/client-go/plugin/pkg/client/auth" +) + +func main() { + if err := cli.Run(); err != nil { + log.Fatal(err) + } +} diff --git a/hack/generate/samples/ansible/generate.go b/hack/generate/samples/ansible/generate.go index c797f4d..645a91b 100644 --- a/hack/generate/samples/ansible/generate.go +++ b/hack/generate/samples/ansible/generate.go @@ -21,13 +21,9 @@ import ( log "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kubebuilder/v4/pkg/cli" - cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3" - "sigs.k8s.io/kubebuilder/v4/pkg/plugin" - kustomizev2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2" - "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang" "github.com/operator-framework/ansible-operator-plugins/hack/generate/samples/internal/pkg" - "github.com/operator-framework/ansible-operator-plugins/pkg/plugins/ansible/v1" + ansiblecli "github.com/operator-framework/ansible-operator-plugins/internal/cmd/ansible-cli/cli" "github.com/operator-framework/ansible-operator-plugins/pkg/testutils/command" "github.com/operator-framework/ansible-operator-plugins/pkg/testutils/e2e" "github.com/operator-framework/ansible-operator-plugins/pkg/testutils/sample" @@ -43,24 +39,7 @@ var memcachedGVK = schema.GroupVersionKind{ } func getCli() *cli.CLI { - ansibleBundle, _ := plugin.NewBundleWithOptions( - plugin.WithName(golang.DefaultNameQualifier), - plugin.WithVersion(ansible.Plugin{}.Version()), - plugin.WithPlugins(kustomizev2.Plugin{}, ansible.Plugin{}), - ) - - c, err := cli.New( - cli.WithCommandName("cli"), - cli.WithVersion("v0.0.0"), - cli.WithPlugins( - ansibleBundle, - ), - cli.WithDefaultPlugins(cfgv3.Version, ansibleBundle), - cli.WithDefaultProjectVersion(cfgv3.Version), - cli.WithCompletion(), - ) - pkg.CheckError("getting cli implementation:", err) - return c + return ansiblecli.GetPluginsCLI() } func GenerateMemcachedSamples(rootPath string) []sample.Sample { diff --git a/internal/cmd/ansible-cli/cli/cli.go b/internal/cmd/ansible-cli/cli/cli.go new file mode 100644 index 0000000..18a9047 --- /dev/null +++ b/internal/cmd/ansible-cli/cli/cli.go @@ -0,0 +1,67 @@ +// Copyright 2025 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cli + +import ( + "fmt" + "log" + "runtime" + + "github.com/operator-framework/ansible-operator-plugins/pkg/plugins/ansible/v1" + + ver "github.com/operator-framework/ansible-operator-plugins/internal/version" + "sigs.k8s.io/kubebuilder/v4/pkg/cli" + cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3" + "sigs.k8s.io/kubebuilder/v4/pkg/plugin" + kustomizev2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2" +) + +func Run() error { + c := GetPluginsCLI() + return c.Run() +} + +func GetPluginsCLI() *cli.CLI { + ansibleBundle, _ := plugin.NewBundleWithOptions( + plugin.WithName(ansible.Plugin{}.Name()), + plugin.WithVersion(ansible.Plugin{}.Version()), + plugin.WithPlugins( + kustomizev2.Plugin{}, + ansible.Plugin{}, + ), + ) + + c, err := cli.New( + cli.WithCommandName("ansible-cli"), + cli.WithVersion(makeVersionString()), + cli.WithPlugins( + ansibleBundle, + ), + cli.WithDefaultPlugins(cfgv3.Version, ansibleBundle), + cli.WithDefaultProjectVersion(cfgv3.Version), + cli.WithCompletion(), + ) + + if err != nil { + log.Fatal(err) + } + + return c +} + +func makeVersionString() string { + return fmt.Sprintf("ansible-cli version: %q, commit: %q, kubernetes version: %q, go version: %q, GOOS: %q, GOARCH: %q", + ver.GitVersion, ver.GitCommit, ver.KubernetesVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH) +} diff --git a/pkg/plugins/ansible/v1/plugin.go b/pkg/plugins/ansible/v1/plugin.go index f712b2e..20ba9df 100644 --- a/pkg/plugins/ansible/v1/plugin.go +++ b/pkg/plugins/ansible/v1/plugin.go @@ -18,11 +18,9 @@ import ( "sigs.k8s.io/kubebuilder/v4/pkg/config" cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3" "sigs.k8s.io/kubebuilder/v4/pkg/plugin" - - "github.com/operator-framework/ansible-operator-plugins/pkg/plugins" ) -const pluginName = "base.ansible" + plugins.DefaultNameQualifier +const pluginName = "ansible.operatorframework.io" var ( pluginVersion = plugin.Version{Number: 1} diff --git a/testdata/memcached-molecule-operator/PROJECT b/testdata/memcached-molecule-operator/PROJECT index f1aba08..da1a95d 100644 --- a/testdata/memcached-molecule-operator/PROJECT +++ b/testdata/memcached-molecule-operator/PROJECT @@ -4,7 +4,7 @@ # More info: https://book.kubebuilder.io/reference/project-config.html domain: example.com layout: -- go.kubebuilder.io/v1 +- ansible.operatorframework.io/v1 multigroup: true projectName: memcached-molecule-operator resources: