-
Notifications
You must be signed in to change notification settings - Fork 27
Add standalone ansible-cli command and release binaries #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/dist | ||
**/bin/ | ||
ansible-operator | ||
ansible-cli | ||
|
||
# Test artifacts | ||
**/testbin/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not include this code here. Reference: operator-sdk/hack/generate/samples/generate_testdata.go#L30-L37 c/c @acornett21 ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the current approach follows a deliberate design choice made in #4 PR, after which we are now generating the testdata on the fly using the helper library. This change is a continuation of the existing pattern. I think we are not breaking the testdata generation flow or logic. |
||
} | ||
|
||
func GenerateMemcachedSamples(rootPath string) []sample.Sample { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought in some names:
ansdk
ansctl
opsible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc: @acornett21 for thoughts.
I liked the
ansdk
naming. If we all agree with this, we can rename it.