@@ -16,19 +16,26 @@ package up
16
16
17
17
import (
18
18
"fmt"
19
+ "log"
19
20
"os"
20
21
"os/exec"
21
22
"os/signal"
22
23
"os/user"
23
24
"path/filepath"
25
+ "runtime"
24
26
"strings"
25
27
"syscall"
26
28
27
29
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
28
30
cmdError "github.com/operator-framework/operator-sdk/commands/operator-sdk/error"
31
+ ansibleOperator "github.com/operator-framework/operator-sdk/pkg/ansible/operator"
32
+ proxy "github.com/operator-framework/operator-sdk/pkg/ansible/proxy"
29
33
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
30
-
34
+ sdkVersion "github.com/operator-framework/operator-sdk/version"
35
+ "github.com/sirupsen/logrus"
31
36
"github.com/spf13/cobra"
37
+ "sigs.k8s.io/controller-runtime/pkg/client/config"
38
+ "sigs.k8s.io/controller-runtime/pkg/manager"
32
39
)
33
40
34
41
func NewLocalCmd () * cobra.Command {
@@ -66,8 +73,15 @@ const (
66
73
func upLocalFunc (cmd * cobra.Command , args []string ) {
67
74
mustKubeConfig ()
68
75
cmdutil .MustInProjectRoot ()
69
- c := cmdutil .GetConfig ()
70
- upLocal (c .ProjectName )
76
+ switch cmdutil .GetOperatorType () {
77
+ case cmdutil .OperatorTypeGo :
78
+ c := cmdutil .GetConfig ()
79
+ upLocal (c .ProjectName )
80
+ case cmdutil .OperatorTypeAnsible :
81
+ upLocalAnsible ()
82
+ default :
83
+ cmdError .ExitWithError (cmdError .ExitError , fmt .Errorf ("failed to determine operator type" ))
84
+ }
71
85
}
72
86
73
87
// mustKubeConfig checks if the kubeconfig file exists.
@@ -112,3 +126,37 @@ func upLocal(projectName string) {
112
126
cmdError .ExitWithError (cmdError .ExitError , fmt .Errorf ("failed to run operator locally: %v" , err ))
113
127
}
114
128
}
129
+
130
+ func upLocalAnsible () {
131
+ mgr , err := manager .New (config .GetConfigOrDie (), manager.Options {Namespace : namespace })
132
+ if err != nil {
133
+ log .Fatal (err )
134
+ }
135
+
136
+ printVersion ()
137
+ done := make (chan error )
138
+
139
+ // start the proxy
140
+ proxy .RunProxy (done , proxy.Options {
141
+ Address : "localhost" ,
142
+ Port : 8888 ,
143
+ KubeConfig : mgr .GetConfig (),
144
+ })
145
+
146
+ // start the operator
147
+ go ansibleOperator .Run (done , mgr , namespace )
148
+
149
+ // wait for either to finish
150
+ err = <- done
151
+ if err == nil {
152
+ logrus .Info ("Exiting" )
153
+ } else {
154
+ logrus .Fatal (err .Error ())
155
+ }
156
+ }
157
+
158
+ func printVersion () {
159
+ logrus .Infof ("Go Version: %s" , runtime .Version ())
160
+ logrus .Infof ("Go OS/Arch: %s/%s" , runtime .GOOS , runtime .GOARCH )
161
+ logrus .Infof ("operator-sdk Version: %v" , sdkVersion .Version )
162
+ }
0 commit comments