Skip to content

Commit

Permalink
Merge branch 'master' into crd-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
estroz committed Apr 15, 2019
2 parents 0d71c07 + a139fdf commit 6dc5d8b
Show file tree
Hide file tree
Showing 58 changed files with 817 additions and 231 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

### Changed

- When Helm operator projects are created, the SDK now generates RBAC rules in `deploy/role.yaml` based on the chart's default manifest. ([#1188](https://github.com/operator-framework/operator-sdk/pull/1188))
- When debug level is 3 or higher, we will set the klog verbosity to that level. ([#1322](https://github.com/operator-framework/operator-sdk/pull/1322))

### Deprecated

### Removed

- The SDK will no longer run `defaulter-gen` on running `operator-sdk generate k8s`. Defaulting for CRDs should be handled with mutating admission webhooks. ([#1288](https://github.com/operator-framework/operator-sdk/pull/1288))

### Bug Fixes

## v0.7.0
Expand Down
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions cmd/operator-sdk/build/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func buildFunc(cmd *cobra.Command, args []string) error {
}

if enableTests {
if projutil.GetOperatorType() == projutil.OperatorTypeGo {
if projutil.IsOperatorGo() {
testBinary := filepath.Join(absProjectPath, scaffold.BuildBinDir, projectName+"-test")
goTestBuildArgs := append(append([]string{"test"}, goTrimFlags...), "-c", "-o", testBinary, testLocationBuild+"/...")
buildTestCmd := exec.Command("go", goTestBuildArgs...)
Expand All @@ -212,8 +212,7 @@ func buildFunc(cmd *cobra.Command, args []string) error {
}

s := &scaffold.Scaffold{}
t := projutil.GetOperatorType()
switch t {
switch t := projutil.GetOperatorType(); t {
case projutil.OperatorTypeGo:
err = s.Execute(cfg,
&scaffold.TestFrameworkDockerfile{},
Expand All @@ -225,7 +224,7 @@ func buildFunc(cmd *cobra.Command, args []string) error {
case projutil.OperatorTypeHelm:
return fmt.Errorf("test scaffolding for Helm Operators is not implemented")
default:
return fmt.Errorf("unknown operator type '%v'", t)
return projutil.ErrUnknownOperatorType{}
}

if err != nil {
Expand Down
21 changes: 0 additions & 21 deletions cmd/operator-sdk/internal/genutil/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func K8sCodegen(hf string) error {
binDir := filepath.Join(wd, scaffold.BuildBinDir)

genDirs := []string{
"./cmd/defaulter-gen",
"./cmd/client-gen",
"./cmd/lister-gen",
"./cmd/informer-gen",
Expand All @@ -63,10 +62,6 @@ func K8sCodegen(hf string) error {
if err = withHeaderFile(hf, fdc); err != nil {
return err
}
fd := func(a string) error { return defaulterGen(binDir, repoPkg, a, gvMap) }
if err = withHeaderFile(hf, fd); err != nil {
return err
}

log.Info("Code-generation complete.")
return nil
Expand All @@ -88,19 +83,3 @@ func deepcopyGen(binDir, repoPkg, hf string, gvMap map[string][]string) (err err
}
return nil
}

func defaulterGen(binDir, repoPkg, hf string, gvMap map[string][]string) (err error) {
apisPkg := filepath.Join(repoPkg, scaffold.ApisDir)
args := []string{
"--input-dirs", createFQApis(apisPkg, gvMap),
"--output-file-base", "zz_generated.defaults",
// defaulter-gen requires a boilerplate file. Either use header or an
// empty file if header is empty.
"--go-header-file", hf,
}
cmd := exec.Command(filepath.Join(binDir, "defaulter-gen"), args...)
if err = projutil.ExecCmd(cmd); err != nil {
return fmt.Errorf("failed to perform defaulter code-generation: %v", err)
}
return nil
}
15 changes: 13 additions & 2 deletions cmd/operator-sdk/new/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import (
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func NewCmd() *cobra.Command {
Expand Down Expand Up @@ -280,6 +282,15 @@ func doHelmScaffold() error {
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, chart.GetValues().GetRaw())

k8sCfg, err := config.GetConfig()
if err != nil {
return fmt.Errorf("failed to get kubernetes config: %s", err)
}
roleScaffold, err := helm.CreateRoleScaffold(k8sCfg, chart, isClusterScoped)
if err != nil {
return fmt.Errorf("failed to generate role scaffold: %s", err)
}

s := &scaffold.Scaffold{}
err = s.Execute(cfg,
&helm.Dockerfile{},
Expand All @@ -288,7 +299,7 @@ func doHelmScaffold() error {
ChartName: chart.GetMetadata().GetName(),
},
&scaffold.ServiceAccount{},
&scaffold.Role{IsClusterScoped: isClusterScoped},
roleScaffold,
&scaffold.RoleBinding{IsClusterScoped: isClusterScoped},
&helm.Operator{IsClusterScoped: isClusterScoped},
&scaffold.CRD{Resource: resource},
Expand All @@ -309,7 +320,7 @@ func doHelmScaffold() error {

func verifyFlags() error {
if operatorType != projutil.OperatorTypeGo && operatorType != projutil.OperatorTypeAnsible && operatorType != projutil.OperatorTypeHelm {
return fmt.Errorf("value of --type can only be `go`, `ansible`, or `helm`")
return errors.Wrap(projutil.ErrUnknownOperatorType{Type: operatorType}, "value of --type can only be `go`, `ansible`, or `helm`")
}
if operatorType != projutil.OperatorTypeAnsible && generatePlaybook {
return fmt.Errorf("value of --generate-playbook can only be used with --type `ansible`")
Expand Down
4 changes: 2 additions & 2 deletions cmd/operator-sdk/test/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
case projutil.OperatorTypeAnsible:
testCmd = []string{"/" + ansible.BuildTestFrameworkAnsibleTestScriptFile}
case projutil.OperatorTypeHelm:
log.Fatal("`test cluster` for Helm operators is not implemented")
return fmt.Errorf("`test cluster` for Helm operators is not implemented")
default:
log.Fatal("Failed to determine operator type")
return projutil.ErrUnknownOperatorType{}
}

// cobra prints its help message on error; we silence that here because any errors below
Expand Down
5 changes: 2 additions & 3 deletions cmd/operator-sdk/test/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ func newTestLocalCmd() *cobra.Command {
}

func testLocalFunc(cmd *cobra.Command, args []string) error {
t := projutil.GetOperatorType()
switch t {
switch t := projutil.GetOperatorType(); t {
case projutil.OperatorTypeGo:
return testLocalGoFunc(cmd, args)
case projutil.OperatorTypeAnsible:
return testLocalAnsibleFunc(cmd, args)
case projutil.OperatorTypeHelm:
return fmt.Errorf("`test local` for Helm operators is not implemented")
}
return fmt.Errorf("unknown operator type '%v'", t)
return projutil.ErrUnknownOperatorType{}
}

func testLocalAnsibleFunc(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 2 additions & 3 deletions cmd/operator-sdk/up/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ func upLocalFunc(cmd *cobra.Command, args []string) error {
}
log.Infof("Using namespace %s.", namespace)

t := projutil.GetOperatorType()
switch t {
switch t := projutil.GetOperatorType(); t {
case projutil.OperatorTypeGo:
return upLocal()
case projutil.OperatorTypeAnsible:
return upLocalAnsible()
case projutil.OperatorTypeHelm:
return upLocalHelm()
}
return fmt.Errorf("unknown operator type '%v'", t)
return projutil.ErrUnknownOperatorType{}
}

func upLocal() error {
Expand Down
10 changes: 8 additions & 2 deletions doc/ansible/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ Kubernetes deployment manifests are generated in `deploy/operator.yaml`. The
deployment image in this file needs to be modified from the placeholder
`REPLACE_IMAGE` to the previous built image. To do this run:
```
$ sed -i 's|REPLACE_IMAGE|quay.io/example/memcached-operator:v0.0.1|g' deploy/operator.yaml
$ sed -i 's|{{ REPLACE_IMAGE }}|quay.io/example/memcached-operator:v0.0.1|g' deploy/operator.yaml
```

The `imagePullPolicy` also requires an update. To do this run:
```
$ sed -i 's|{{ pull_policy\|default('\''Always'\'') }}|Always|g' deploy/operator.yaml
```

If you created your operator using `--cluster-scoped=true`, update the service account namespace in the generated `ClusterRoleBinding` to match where you are deploying your operator.
Expand All @@ -286,8 +291,9 @@ $ sed -i "s|REPLACE_NAMESPACE|$OPERATOR_NAMESPACE|g" deploy/role_binding.yaml
**Note**
If you are performing these steps on OSX, use the following commands instead:
```
$ sed -i "" 's|REPLACE_IMAGE|quay.io/example/memcached-operator:v0.0.1|g' deploy/operator.yaml
$ sed -i "" 's|{{ REPLACE_IMAGE }}|quay.io/example/memcached-operator:v0.0.1|g' deploy/operator.yaml
$ sed -i "" "s|REPLACE_NAMESPACE|$OPERATOR_NAMESPACE|g" deploy/role_binding.yaml
$ sed -i "" 's|{{ pull_policy\|default('\''Always'\'') }}|Always|g' deploy/operator.yaml
```
Deploy the memcached-operator:
Expand Down
7 changes: 6 additions & 1 deletion doc/helm/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ powered by Helm using tools and libraries provided by the Operator SDK.
- [kubectl][kubectl_tool] version v1.11.3+.
- [dep][dep_tool] version v0.5.0+. (Optional if you aren't installing from source)
- [go][go_tool] version v1.10+. (Optional if you aren't installing from source)
- Access to a Kubernetes v.1.11.3+ cluster.
- Access to a Kubernetes v1.11.3+ cluster.

**Note**: This guide uses [minikube][minikube_tool] version v0.25.0+ as the
local Kubernetes cluster and [quay.io][quay_link] for the public registry.
Expand Down Expand Up @@ -53,6 +53,11 @@ This creates the nginx-operator project specifically for watching the
Nginx resource with APIVersion `example.com/v1alpha1` and Kind
`Nginx`.

For Helm-based projects, `operator-sdk new` also generates the RBAC rules
in `deploy/role.yaml` based on the resources that would be deployed by the
chart's default manifest. Be sure to double check that the rules generated
in `deploy/role.yaml` meet the operator's permission requirements.

To learn more about the project directory structure, see the
[project layout][layout_doc] doc.

Expand Down
1 change: 0 additions & 1 deletion doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Prints the most recent Golang packages and versions required by operators. Print
```console
$ operator-sdk print-deps --as-file
required = [
"k8s.io/code-generator/cmd/defaulter-gen",
"k8s.io/code-generator/cmd/deepcopy-gen",
"k8s.io/code-generator/cmd/conversion-gen",
"k8s.io/code-generator/cmd/client-gen",
Expand Down
2 changes: 1 addition & 1 deletion doc/user/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ In the above example, we add the zap flagset to the operator's command line flag
By default, `zap.Logger()` will return a logger that is ready for production use. It uses a JSON encoder, logs starting at the `info` level, and has [sampling][zap_sampling] enabled. To customize the default behavior, users can use the zap flagset and specify flags on the command line. The zap flagset includes the following flags that can be used to configure the logger:
* `--zap-devel` - Enables the zap development config (changes defaults to console encoder, debug log level, and disables sampling) (default: `false`)
* `--zap-encoder` string - Sets the zap log encoding (`json` or `console`)
* `--zap-level` string or integer - Sets the zap log level (`debug`, `info`, `error`, or an integer value greater than 0)
* `--zap-level` string or integer - Sets the zap log level (`debug`, `info`, `error`, or an integer value greater than 0). If 4 or greater the verbosity of client-go will be set to this level.
* `--zap-sample` - Enables zap's sampling mode. Sampling will be disabled for integer log levels greater than 1.


Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/scaffold/ansible/ao_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

//DockerfileHybrid - Dockerfile for a hybrid operator
type AoLogs struct {
input.Input
StaticInput
}

// GetInput - gets the input
Expand Down
9 changes: 5 additions & 4 deletions internal/pkg/scaffold/ansible/build_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ func (b *BuildDockerfile) GetInput() (input.Input, error) {
b.Path = filepath.Join(scaffold.BuildDir, BuildDockerfileFile)
}
b.TemplateBody = buildDockerfileAnsibleTmpl
b.Delims = AnsibleDelims
b.RolesDir = RolesDir
b.ImageTag = strings.TrimSuffix(version.Version, "+git")
return b.Input, nil
}

const buildDockerfileAnsibleTmpl = `FROM quay.io/operator-framework/ansible-operator:{{.ImageTag}}
const buildDockerfileAnsibleTmpl = `FROM quay.io/operator-framework/ansible-operator:[[.ImageTag]]
COPY watches.yaml ${HOME}/watches.yaml
COPY {{.RolesDir}}/ ${HOME}/{{.RolesDir}}/
{{- if .GeneratePlaybook }}
COPY [[.RolesDir]]/ ${HOME}/[[.RolesDir]]/
[[- if .GeneratePlaybook ]]
COPY playbook.yml ${HOME}/playbook.yml
{{- end }}
[[- end ]]
`
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const BuildTestFrameworkAnsibleTestScriptFile = "ansible-test.sh"

type BuildTestFrameworkAnsibleTestScript struct {
input.Input
StaticInput
}

// GetInput - gets the input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const BuildTestFrameworkDockerfileFile = "Dockerfile"

type BuildTestFrameworkDockerfile struct {
input.Input
StaticInput
}

// GetInput - gets the input
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/scaffold/ansible/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ const (
MoleculeDefaultDir = MoleculeDir + filePathSep + "default"
MoleculeTestLocalDir = MoleculeDir + filePathSep + "test-local"
)

// Arrays can't be constants but this should be a constant
var AnsibleDelims = [2]string{"[[", "]]"}
Loading

0 comments on commit 6dc5d8b

Please sign in to comment.