Skip to content

Commit ed92d36

Browse files
[ansible/helm] remove operator-sdk binary from ansible/helm base images (#3331)
* [ansible] generate binary to run ansible operator Remove the subcommand operator-sdk exec-entrypoint which is only valid for Ansible/Helm-based Operators. Add the main.go to run the operators in cmd/<helm|ansible>-operator/main.go Build cmd/<helm|ansible>-operator/main.go for Ansible/Helm base images. The script buid-<ansible|helm>-image.sh builds the binary from cmd/ansible|helm-operator/main.go. The Dockerfile scaffolding now copies this binary instead of SDK's binary. The entry-point script can now run the generated base-image binary instead of exec-entrypoint command. The motivation to do so is to remove `exec-entrypoint` command which was only used to build ansible/helm base images. With this PR, both the base images have an independent entry-point and do not include operator sdk binary. * [helm] generate binary to run helm operator * [ansible/helm] make changes to e2e tests * [ansible/helm] remove exec-entrypoint and add changelog fragment
1 parent b8862df commit ed92d36

File tree

9 files changed

+57
-141
lines changed

9 files changed

+57
-141
lines changed

cmd/ansible-operator/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2020 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 main
16+
17+
import (
18+
log "github.com/sirupsen/logrus"
19+
"github.com/spf13/pflag"
20+
logf "sigs.k8s.io/controller-runtime/pkg/log"
21+
22+
"github.com/operator-framework/operator-sdk/pkg/ansible"
23+
aoflags "github.com/operator-framework/operator-sdk/pkg/ansible/flags"
24+
"github.com/operator-framework/operator-sdk/pkg/log/zap"
25+
)
26+
27+
func main() {
28+
flags := aoflags.AddTo(pflag.CommandLine)
29+
pflag.Parse()
30+
logf.SetLogger(zap.Logger())
31+
32+
if err := ansible.Run(flags); err != nil {
33+
log.Fatal(err)
34+
}
35+
}
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 The Operator-SDK Authors
1+
// Copyright 2020 The Operator-SDK Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,37 +12,24 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package execentrypoint
15+
package main
1616

1717
import (
18+
log "github.com/sirupsen/logrus"
19+
"github.com/spf13/pflag"
20+
logf "sigs.k8s.io/controller-runtime/pkg/log"
21+
1822
"github.com/operator-framework/operator-sdk/pkg/helm"
1923
hoflags "github.com/operator-framework/operator-sdk/pkg/helm/flags"
2024
"github.com/operator-framework/operator-sdk/pkg/log/zap"
21-
22-
log "github.com/sirupsen/logrus"
23-
"github.com/spf13/cobra"
24-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2525
)
2626

27-
// newRunHelmCmd returns a command that will run a helm operator.
28-
func newRunHelmCmd() *cobra.Command {
29-
var flags *hoflags.HelmOperatorFlags
30-
runHelmCmd := &cobra.Command{
31-
Use: "helm",
32-
Short: "Runs as a helm operator",
33-
Long: `Runs as a helm operator. This is intended to be used when running
34-
in a Pod inside a cluster. Developers wanting to run their operator locally
35-
should use 'run local' instead.`,
36-
RunE: func(cmd *cobra.Command, args []string) error {
37-
logf.SetLogger(zap.Logger())
27+
func main() {
28+
flags := hoflags.AddTo(pflag.CommandLine)
29+
pflag.Parse()
30+
logf.SetLogger(zap.Logger())
3831

39-
if err := helm.Run(flags); err != nil {
40-
log.Fatal(err)
41-
}
42-
return nil
43-
},
32+
if err := helm.Run(flags); err != nil {
33+
log.Fatal(err)
4434
}
45-
flags = hoflags.AddTo(runHelmCmd.Flags())
46-
47-
return runHelmCmd
4835
}

cmd/operator-sdk/cli/legacy.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/bundle"
2222
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cleanup"
2323
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
24-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/execentrypoint"
2524
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
2625
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
2726
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
@@ -76,7 +75,6 @@ func GetCLIRoot() *cobra.Command {
7675
bundle.NewCmdLegacy(),
7776
cleanup.NewCmdLegacy(),
7877
completion.NewCmd(),
79-
execentrypoint.NewCmd(),
8078
generate.NewCmdLegacy(),
8179
migrate.NewCmd(),
8280
new.NewCmd(),

cmd/operator-sdk/execentrypoint/ansible.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

cmd/operator-sdk/execentrypoint/cmd.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

hack/image/build-ansible-image.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ BASEIMAGEDIR="$TMPDIR/ansible-operator"
1212
mkdir -p "$BASEIMAGEDIR"
1313
go build -o $BASEIMAGEDIR/scaffold-ansible-image ./hack/image/ansible/scaffold-ansible-image.go
1414

15+
# build binary for specific target platform (for purposes of base image only)
16+
env GOOS=linux GOARCH=amd64 go build -o $BASEIMAGEDIR/ansible-operator-dev-linux-gnu ./cmd/ansible-operator/main.go
17+
1518
# build operator binary and base image
1619
pushd "$BASEIMAGEDIR"
1720
./scaffold-ansible-image
1821

1922
mkdir -p build/_output/bin/
20-
cp $ROOTDIR/build/operator-sdk-dev-linux-gnu build/_output/bin/ansible-operator
23+
cp $BASEIMAGEDIR/ansible-operator-dev-linux-gnu build/_output/bin/ansible-operator
2124
operator-sdk build $1
2225
# If using a kind cluster, load the image into all nodes.
2326
load_image_if_kind "$1"

hack/image/build-helm-image.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ BASEIMAGEDIR="$TMPDIR/helm-operator"
1212
mkdir -p "$BASEIMAGEDIR"
1313
go build -o $BASEIMAGEDIR/scaffold-helm-image ./hack/image/helm/scaffold-helm-image.go
1414

15+
# build binary for specific target platform (for purposes of base image only)
16+
env GOOS=linux GOARCH=amd64 go build -o $BASEIMAGEDIR/helm-operator-dev-linux-gnu ./cmd/helm-operator/main.go
17+
1518
# build operator binary and base image
1619
pushd "$BASEIMAGEDIR"
1720
./scaffold-helm-image
1821

1922
mkdir -p build/_output/bin/
20-
cp $ROOTDIR/build/operator-sdk-dev-linux-gnu build/_output/bin/helm-operator
23+
cp $BASEIMAGEDIR/helm-operator-dev-linux-gnu build/_output/bin/helm-operator
2124
operator-sdk build $1
2225
# If using a kind cluster, load the image into all nodes.
2326
load_image_if_kind "$1"

internal/scaffold/ansible/entrypoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ func (e *Entrypoint) GetInput() (input.Input, error) {
3737
const entrypointTmpl = `#!/bin/bash -e
3838
3939
cd $HOME
40-
exec ${OPERATOR} exec-entrypoint ansible --watches-file=$HOME/watches.yaml $@
40+
exec ${OPERATOR} --watches-file=$HOME/watches.yaml $@
4141
`

internal/scaffold/helm/entrypoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ func (e *Entrypoint) GetInput() (input.Input, error) {
3737
const entrypointTmpl = `#!/bin/sh -e
3838
3939
cd $HOME
40-
exec ${OPERATOR} exec-entrypoint helm --watches-file=$HOME/watches.yaml $@
40+
exec ${OPERATOR} --watches-file=$HOME/watches.yaml $@
4141
`

0 commit comments

Comments
 (0)