diff --git a/cmd/ansible-operator/main.go b/cmd/ansible-operator/main.go new file mode 100644 index 0000000000..101d180974 --- /dev/null +++ b/cmd/ansible-operator/main.go @@ -0,0 +1,35 @@ +// Copyright 2020 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/sirupsen/logrus" + "github.com/spf13/pflag" + logf "sigs.k8s.io/controller-runtime/pkg/log" + + "github.com/operator-framework/operator-sdk/pkg/ansible" + aoflags "github.com/operator-framework/operator-sdk/pkg/ansible/flags" + "github.com/operator-framework/operator-sdk/pkg/log/zap" +) + +func main() { + flags := aoflags.AddTo(pflag.CommandLine) + pflag.Parse() + logf.SetLogger(zap.Logger()) + + if err := ansible.Run(flags); err != nil { + log.Fatal(err) + } +} diff --git a/cmd/operator-sdk/execentrypoint/helm.go b/cmd/helm-operator/main.go similarity index 53% rename from cmd/operator-sdk/execentrypoint/helm.go rename to cmd/helm-operator/main.go index 27ee9fc396..f76ba5d911 100644 --- a/cmd/operator-sdk/execentrypoint/helm.go +++ b/cmd/helm-operator/main.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Operator-SDK Authors +// Copyright 2020 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. @@ -12,37 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -package execentrypoint +package main import ( + log "github.com/sirupsen/logrus" + "github.com/spf13/pflag" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/operator-framework/operator-sdk/pkg/helm" hoflags "github.com/operator-framework/operator-sdk/pkg/helm/flags" "github.com/operator-framework/operator-sdk/pkg/log/zap" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - logf "sigs.k8s.io/controller-runtime/pkg/log" ) -// newRunHelmCmd returns a command that will run a helm operator. -func newRunHelmCmd() *cobra.Command { - var flags *hoflags.HelmOperatorFlags - runHelmCmd := &cobra.Command{ - Use: "helm", - Short: "Runs as a helm operator", - Long: `Runs as a helm operator. This is intended to be used when running -in a Pod inside a cluster. Developers wanting to run their operator locally -should use 'run local' instead.`, - RunE: func(cmd *cobra.Command, args []string) error { - logf.SetLogger(zap.Logger()) +func main() { + flags := hoflags.AddTo(pflag.CommandLine) + pflag.Parse() + logf.SetLogger(zap.Logger()) - if err := helm.Run(flags); err != nil { - log.Fatal(err) - } - return nil - }, + if err := helm.Run(flags); err != nil { + log.Fatal(err) } - flags = hoflags.AddTo(runHelmCmd.Flags()) - - return runHelmCmd } diff --git a/cmd/operator-sdk/cli/legacy.go b/cmd/operator-sdk/cli/legacy.go index 61e37af5dd..d1c84e0c47 100644 --- a/cmd/operator-sdk/cli/legacy.go +++ b/cmd/operator-sdk/cli/legacy.go @@ -21,7 +21,6 @@ import ( "github.com/operator-framework/operator-sdk/cmd/operator-sdk/bundle" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/cleanup" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion" - "github.com/operator-framework/operator-sdk/cmd/operator-sdk/execentrypoint" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/new" @@ -76,7 +75,6 @@ func GetCLIRoot() *cobra.Command { bundle.NewCmdLegacy(), cleanup.NewCmdLegacy(), completion.NewCmd(), - execentrypoint.NewCmd(), generate.NewCmdLegacy(), migrate.NewCmd(), new.NewCmd(), diff --git a/cmd/operator-sdk/execentrypoint/ansible.go b/cmd/operator-sdk/execentrypoint/ansible.go deleted file mode 100644 index 6d6e1300d6..0000000000 --- a/cmd/operator-sdk/execentrypoint/ansible.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2019 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 execentrypoint - -import ( - "fmt" - "os" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - logf "sigs.k8s.io/controller-runtime/pkg/log" - - "github.com/operator-framework/operator-sdk/pkg/ansible" - aoflags "github.com/operator-framework/operator-sdk/pkg/ansible/flags" - "github.com/operator-framework/operator-sdk/pkg/log/zap" -) - -// newRunAnsibleCmd returns a command that will run an ansible operator. -func newRunAnsibleCmd() *cobra.Command { - var flags *aoflags.AnsibleOperatorFlags - runAnsibleCmd := &cobra.Command{ - Use: "ansible", - Short: "Runs as an ansible operator", - Long: `Runs as an ansible operator. This is intended to be used when running -in a Pod inside a cluster. Developers wanting to run their operator locally -should use 'run local' instead.`, - RunE: func(cmd *cobra.Command, args []string) error { - logf.SetLogger(zap.Logger()) - if err := setAnsibleEnvVars(flags); err != nil { - log.Fatal(err) - } - if err := ansible.Run(flags); err != nil { - log.Fatal(err) - } - return nil - }, - } - flags = aoflags.AddTo(runAnsibleCmd.Flags()) - - return runAnsibleCmd -} - -// setAnsibleEnvVars will set Ansible-defined environment variables from CLI flags. -func setAnsibleEnvVars(flags *aoflags.AnsibleOperatorFlags) error { - if flags != nil { - if len(flags.AnsibleRolesPath) > 0 { - if err := os.Setenv(aoflags.AnsibleRolesPathEnvVar, flags.AnsibleRolesPath); err != nil { - return fmt.Errorf("failed to set %s environment variable: (%v)", aoflags.AnsibleRolesPathEnvVar, err) - } - log.Infof("Set the value %v for environment variable %v.", - flags.AnsibleRolesPath, aoflags.AnsibleRolesPathEnvVar) - } - if len(flags.AnsibleCollectionsPath) > 0 { - if err := os.Setenv(aoflags.AnsibleCollectionsPathEnvVar, flags.AnsibleCollectionsPath); err != nil { - return fmt.Errorf("failed to set %s environment variable: (%v)", aoflags.AnsibleCollectionsPathEnvVar, err) - } - log.Infof("Set the value %v for environment variable %v.", - flags.AnsibleCollectionsPath, aoflags.AnsibleCollectionsPathEnvVar) - } - } - return nil -} diff --git a/cmd/operator-sdk/execentrypoint/cmd.go b/cmd/operator-sdk/execentrypoint/cmd.go deleted file mode 100644 index 9785cdd392..0000000000 --- a/cmd/operator-sdk/execentrypoint/cmd.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 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 execentrypoint - -import "github.com/spf13/cobra" - -// NewCmd returns a command that contains subcommands to run specific -// operator types. -func NewCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "exec-entrypoint", - Short: "Runs a generic operator", - Long: `Runs a generic operator. This is intended to be used when running -in a Pod inside a cluster. Developers wanting to run their operator locally -should use 'run local' instead.`, - Hidden: true, - } - - cmd.AddCommand( - newRunAnsibleCmd(), - newRunHelmCmd(), - ) - return cmd -} diff --git a/hack/image/build-ansible-image.sh b/hack/image/build-ansible-image.sh index 596ddc7ba4..6588bbe146 100755 --- a/hack/image/build-ansible-image.sh +++ b/hack/image/build-ansible-image.sh @@ -12,12 +12,15 @@ BASEIMAGEDIR="$TMPDIR/ansible-operator" mkdir -p "$BASEIMAGEDIR" go build -o $BASEIMAGEDIR/scaffold-ansible-image ./hack/image/ansible/scaffold-ansible-image.go +# build binary for specific target platform (for purposes of base image only) +env GOOS=linux GOARCH=amd64 go build -o $BASEIMAGEDIR/ansible-operator-dev-linux-gnu ./cmd/ansible-operator/main.go + # build operator binary and base image pushd "$BASEIMAGEDIR" ./scaffold-ansible-image mkdir -p build/_output/bin/ -cp $ROOTDIR/build/operator-sdk-dev-linux-gnu build/_output/bin/ansible-operator +cp $BASEIMAGEDIR/ansible-operator-dev-linux-gnu build/_output/bin/ansible-operator operator-sdk build $1 # If using a kind cluster, load the image into all nodes. load_image_if_kind "$1" diff --git a/hack/image/build-helm-image.sh b/hack/image/build-helm-image.sh index 52e55be75d..dcf1f79341 100755 --- a/hack/image/build-helm-image.sh +++ b/hack/image/build-helm-image.sh @@ -12,12 +12,15 @@ BASEIMAGEDIR="$TMPDIR/helm-operator" mkdir -p "$BASEIMAGEDIR" go build -o $BASEIMAGEDIR/scaffold-helm-image ./hack/image/helm/scaffold-helm-image.go +# build binary for specific target platform (for purposes of base image only) +env GOOS=linux GOARCH=amd64 go build -o $BASEIMAGEDIR/helm-operator-dev-linux-gnu ./cmd/helm-operator/main.go + # build operator binary and base image pushd "$BASEIMAGEDIR" ./scaffold-helm-image mkdir -p build/_output/bin/ -cp $ROOTDIR/build/operator-sdk-dev-linux-gnu build/_output/bin/helm-operator +cp $BASEIMAGEDIR/helm-operator-dev-linux-gnu build/_output/bin/helm-operator operator-sdk build $1 # If using a kind cluster, load the image into all nodes. load_image_if_kind "$1" diff --git a/internal/scaffold/ansible/entrypoint.go b/internal/scaffold/ansible/entrypoint.go index 49a5ea0b9e..c559a0436f 100644 --- a/internal/scaffold/ansible/entrypoint.go +++ b/internal/scaffold/ansible/entrypoint.go @@ -37,5 +37,5 @@ func (e *Entrypoint) GetInput() (input.Input, error) { const entrypointTmpl = `#!/bin/bash -e cd $HOME -exec ${OPERATOR} exec-entrypoint ansible --watches-file=$HOME/watches.yaml $@ +exec ${OPERATOR} --watches-file=$HOME/watches.yaml $@ ` diff --git a/internal/scaffold/helm/entrypoint.go b/internal/scaffold/helm/entrypoint.go index 3d04c95b64..0738893962 100644 --- a/internal/scaffold/helm/entrypoint.go +++ b/internal/scaffold/helm/entrypoint.go @@ -37,5 +37,5 @@ func (e *Entrypoint) GetInput() (input.Input, error) { const entrypointTmpl = `#!/bin/sh -e cd $HOME -exec ${OPERATOR} exec-entrypoint helm --watches-file=$HOME/watches.yaml $@ +exec ${OPERATOR} --watches-file=$HOME/watches.yaml $@ `