-
Notifications
You must be signed in to change notification settings - Fork 1.8k
adds migrate
and run ansible
commands
#887
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
Changes from 1 commit
784bd74
0e9a69c
1d004aa
c845851
96b06a2
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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 main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/operator-framework/operator-sdk/internal/util/projutil" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/ansible" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// main renders scaffolds that are required to build the ansible operator base | ||
// image. It is intended for release engineering use only. After running this, | ||
// you can place a binary in `build/_output/bin/ansible-operator` and then run | ||
// `operator-sdk build`. | ||
func main() { | ||
cfg := &input.Config{ | ||
AbsProjectPath: projutil.MustGetwd(), | ||
ProjectName: "ansible-operator", | ||
} | ||
|
||
s := &scaffold.Scaffold{} | ||
err := s.Execute(cfg, | ||
&ansible.DockerfileHybrid{}, | ||
&ansible.Entrypoint{}, | ||
&ansible.UserSetup{}, | ||
) | ||
if err != nil { | ||
log.Fatalf("add scaffold failed: (%v)", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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 cmd | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/internal/util/projutil" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/ansible" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewMigrateCmd returns a command that will add source code to an existing non-go operator | ||
func NewMigrateCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Adds source code to an operator", | ||
Long: `operator-sdk migrate adds a main.go source file and any associated source files for an operator that is not of the "go" type.`, | ||
Run: migrateRun, | ||
} | ||
} | ||
|
||
// migrateRun determines the current operator type and runs the corresponding | ||
// migrate function. | ||
func migrateRun(cmd *cobra.Command, args []string) { | ||
projutil.MustInProjectRoot() | ||
|
||
_ = projutil.CheckAndGetProjectGoPkg() | ||
|
||
opType := projutil.GetOperatorType() | ||
switch opType { | ||
case projutil.OperatorTypeAnsible: | ||
migrateAnsible() | ||
default: | ||
log.Fatalf("operator of type %s cannot be migrated.", opType) | ||
} | ||
} | ||
|
||
// migrateAnsible runs the migration process for an ansible-based operator | ||
func migrateAnsible() { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
log.Fatalf("could not identify current working directory: (%v)", err) | ||
} | ||
|
||
cfg := &input.Config{ | ||
AbsProjectPath: projutil.MustGetwd(), | ||
ProjectName: filepath.Base(wd), | ||
} | ||
|
||
dockerfile := ansible.DockerfileHybrid{ | ||
Watches: true, | ||
Roles: true, | ||
} | ||
_, err = os.Stat("playbook.yaml") | ||
switch { | ||
case err == nil: | ||
dockerfile.Playbook = true | ||
case !os.IsNotExist(err): | ||
log.Fatalf("error trying to stat playbook.yaml: (%v)", err) | ||
} | ||
|
||
dockerfilePath := filepath.Join(scaffold.BuildDir, scaffold.DockerfileFile) | ||
err = os.Rename(dockerfilePath, dockerfilePath+".sdkold") | ||
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 we need to alert the user that we took this action after this finishes IMO. 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. Also, at the end of the command, should we run dep ensure? or should we ask the user to run dep ensure? 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. Agreed to the alerting. I'll log something about it. 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 lean toward not running dep automatically, in part because it will cause the e2e tests to fail in cases like we see here where operator-sdk has changes that aren't in the upstream repo. It makes me think there are enough other cases where the user doesn't want to run |
||
if err != nil { | ||
log.Fatalf("failed to rename Dockerfile: (%v)", err) | ||
} | ||
|
||
s := &scaffold.Scaffold{} | ||
err = s.Execute(cfg, | ||
&ansible.Main{}, | ||
&ansible.GopkgToml{}, | ||
&dockerfile, | ||
&ansible.Entrypoint{}, | ||
&ansible.UserSetup{}, | ||
) | ||
if err != nil { | ||
log.Fatalf("add scaffold failed: (%v)", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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 cmd | ||
|
||
import ( | ||
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/run" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewRunCmd returns a command that contains subcommands to run specific | ||
// operator types. | ||
func NewRunCmd() *cobra.Command { | ||
runCmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Runs a generic operator", | ||
} | ||
|
||
runCmd.AddCommand(run.NewAnsibleCmd()) | ||
return runCmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 run | ||
|
||
import ( | ||
"github.com/operator-framework/operator-sdk/pkg/ansible" | ||
aoflags "github.com/operator-framework/operator-sdk/pkg/ansible/flags" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var flags *aoflags.AnsibleOperatorFlags | ||
|
||
// NewAnsibleCmd returns a command that will run an ansible operator | ||
func NewAnsibleCmd() *cobra.Command { | ||
newCmd := &cobra.Command{ | ||
Use: "ansible", | ||
Short: "Runs as an ansible operator", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ansible.Run(flags) | ||
estroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
flags = aoflags.AddTo(newCmd.Flags()) | ||
|
||
return newCmd | ||
} |
Uh oh!
There was an error while loading. Please reload this page.