Skip to content

Commit 7f575be

Browse files
committed
Merge branch 'master' into refactor/controller-runtime-v0.2.0
2 parents 0fda655 + 9058b02 commit 7f575be

36 files changed

+514
-488
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
### Added
44

5+
- The `operator-sdk olm-catalog gen-csv` command now produces indented JSON for the `alm-examples` annotation. ([#1793](https://github.com/operator-framework/operator-sdk/pull/1793))
6+
- Added flag `--dep-manager` to command [`operator-sdk print-deps`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#print-deps) to specify the type of dependency manager file to print. The choice of dependency manager is inferred from top-level dependency manager files present if `--dep-manager` is not set. ([#1819](https://github.com/operator-framework/operator-sdk/pull/1819))
7+
58
### Changed
69

10+
- The Helm operator now uses the CR name for the release name for newly created CRs. Existing CRs will continue to use their existing UID-based release name. When a release name collision occurs (when CRs of different types share the same name), the second CR will fail to install with an error about a duplicate name. ([#1818](https://github.com/operator-framework/operator-sdk/pull/1818))
11+
- Commands [`olm uninstall`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#uninstall) and [`olm status`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#status) no longer use a `--version` flag to specify OLM version. This information is now retrieved from the running cluster. ([#1634](https://github.com/operator-framework/operator-sdk/pull/1634))
12+
713
### Breaking changes
814

915
- CSV config field `role-path` is now `role-paths` and takes a list of strings. Users can now specify multiple `Role` and `ClusterRole` manifests using `role-paths`. ([#1704](https://github.com/operator-framework/operator-sdk/pull/1704))
@@ -35,9 +41,13 @@
3541

3642
### Removed
3743

44+
- Removed flag `--as-file` from command [`operator-sdk print-deps`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#print-deps), which now only prints packages and versions in dependency manager file format. The choice of dependency manager type is set by `--dep-manager` or inferred from top-level dependency manager files present if `--dep-manager` is not set. ([#1819](https://github.com/operator-framework/operator-sdk/pull/1819))
45+
3846
### Bug Fixes
3947

4048
- Configure the repo path correctly in `operator-sdk add crd` and prevent the command from running outside of an operator project. ([#1660](https://github.com/operator-framework/operator-sdk/pull/1660))
49+
- In the Helm operator, skip owner reference injection for cluster-scoped resources in release manifests. The Helm operator only supports namespace-scoped CRs, and namespaced resources cannot own cluster-scoped resources. ([#1817](https://github.com/operator-framework/operator-sdk/pull/1817))
50+
- Package manifests generated with [`gen-csv`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#gen-csv) respect the `--operator-name` flag, channel names are checked for duplicates before (re-)generation. ([#1693](https://github.com/operator-framework/operator-sdk/pull/1693))
4151

4252
## v0.10.0
4353

@@ -70,6 +80,7 @@
7080
- New flags `--csv-channel` and `--default-channel` for subcommand [`gen-csv`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#gen-csv) that add channels to and update the [package manifest](https://github.com/operator-framework/operator-registry/#manifest-format) in `deploy/olm-catalog/<operator-name>` when generating a new CSV or updating an existing one. ([#1364](https://github.com/operator-framework/operator-sdk/pull/1364))
7181
- Adds `go.mod` and `go.sum` to switch from `dep` to [Go modules](https://github.com/golang/go/wiki/Modules) to manage dependencies for the SDK project itself. ([#1566](https://github.com/operator-framework/operator-sdk/pull/1566))
7282
- New flag `--operator-name` for [`operator-sdk olm-catalog gen-csv`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#gen-csv) to specify the operator name, ex. `memcached-operator`, to use in CSV generation. The project's name is used (old behavior) if `--operator-name` is not set. ([#1571](https://github.com/operator-framework/operator-sdk/pull/1571))
83+
- New flag `--local-operator-flags` for `operator-sdk test local --up-local` to specify flags to run a local operator with during a test. ([#1509](https://github.com/operator-framework/operator-sdk/pull/1509))
7384

7485
### Changed
7586

ci/dockerfiles/ansible-e2e-hybrid.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ ENV OPERATOR=/usr/local/bin/ansible-operator \
2020
HOME=/opt/ansible
2121

2222
# Install python dependencies
23-
RUN (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
23+
# Ensure fresh metadata rather than cached metadata in the base by running
24+
# yum clean all && rm -rf /var/yum/cache/* first
25+
RUN yum clean all && rm -rf /var/cache/yum/* \
26+
&& (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
2427
&& yum install -y python-devel gcc inotify-tools \
2528
&& easy_install pip \
2629
&& pip install -U --no-cache-dir setuptools pip \

ci/dockerfiles/ansible.Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ ENV OPERATOR=/usr/local/bin/ansible-operator \
1818
USER_NAME=ansible-operator\
1919
HOME=/opt/ansible
2020

21-
# Install python dependencies
22-
RUN (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
21+
# Ensure fresh metadata rather than cached metadata in the base by running
22+
# yum clean all && rm -rf /var/yum/cache/* first
23+
RUN yum clean all && rm -rf /var/cache/yum/* \
24+
&& (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
2325
&& yum install -y python-devel gcc inotify-tools \
2426
&& easy_install pip \
2527
&& pip install -U --no-cache-dir setuptools pip \

cmd/operator-sdk/alpha/olm/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func NewInstallCmd() *cobra.Command {
3434
},
3535
}
3636

37+
cmd.Flags().StringVar(&mgr.Version, "version", olm.DefaultVersion, "version of OLM resources to install")
3738
mgr.AddToFlagSet(cmd.Flags())
3839
return cmd
3940
}

cmd/operator-sdk/alpha/olm/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewStatusCmd() *cobra.Command {
2828
Short: "Get the status of the Operator Lifecycle Manager installation in your cluster",
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
if err := mgr.Status(); err != nil {
31-
log.Fatalf("Failed to get OLM status for version %q: %s", mgr.Version, err)
31+
log.Fatalf("Failed to get OLM status: %s", err)
3232
}
3333
return nil
3434
},

cmd/operator-sdk/alpha/olm/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewUninstallCmd() *cobra.Command {
2828
Short: "Uninstall Operator Lifecycle Manager from your cluster",
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
if err := mgr.Uninstall(); err != nil {
31-
log.Fatalf("Failed to uninstall OLM version %q: %s", mgr.Version, err)
31+
log.Fatalf("Failed to uninstall OLM: %s", err)
3232
}
3333
return nil
3434
},

cmd/operator-sdk/internal/genutil/genutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
log "github.com/sirupsen/logrus"
2424
)
2525

26-
// generateWithHeaderFile runs f with a header file path as an arguemnt.
26+
// generateWithHeaderFile runs f with a header file path as an argument.
2727
// If there is no project boilerplate.go.txt file, an empty header file is
2828
// created and its path passed as the argument.
2929
// generateWithHeaderFile is meant to be used with Kubernetes code generators.

cmd/operator-sdk/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var commandsToSkip = map[string]struct{}{
119119
"help": struct{}{},
120120
"completion": struct{}{},
121121
"version": struct{}{},
122+
"print-deps": struct{}{}, // Does not require this logic
122123
}
123124

124125
func skipCheckForCmd(cmd *cobra.Command) (skip bool) {

cmd/operator-sdk/olmcatalog/gen-csv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func genCSVFunc(cmd *cobra.Command, args []string) error {
107107
CSVVersion: csvVersion,
108108
Channel: csvChannel,
109109
ChannelIsDefault: defaultChannel,
110+
OperatorName: operatorName,
110111
},
111112
)
112113
if err != nil {

cmd/operator-sdk/printdeps/cmd.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/spf13/cobra"
2626
)
2727

28-
var asFile bool
28+
var depManager string
2929

3030
func NewCmd() *cobra.Command {
3131
printDepsCmd := &cobra.Command{
@@ -35,14 +35,11 @@ func NewCmd() *cobra.Command {
3535
by this version of the Operator SDK. Versions for these packages should match
3636
those in an operators' go.mod or Gopkg.toml file, depending on the dependency
3737
manager chosen when initializing or migrating a project.
38-
39-
print-deps prints in columnar format by default. Use the --as-file flag to
40-
print in go.mod or Gopkg.toml file format.
4138
`,
4239
RunE: printDepsFunc,
4340
}
4441

45-
printDepsCmd.Flags().BoolVar(&asFile, "as-file", false, "Print dependencies in go.mod or Gopkg.toml file format, depending on the dependency manager chosen when initializing or migrating a project")
42+
printDepsCmd.Flags().StringVar(&depManager, "dep-manager", "", `Dependency manager file type to print (choices: "dep", "modules")`)
4643

4744
return printDepsCmd
4845
}
@@ -51,17 +48,23 @@ func printDepsFunc(cmd *cobra.Command, args []string) error {
5148
if len(args) != 0 {
5249
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
5350
}
51+
projutil.MustInProjectRoot()
5452

55-
if err := printDeps(asFile); err != nil {
56-
return fmt.Errorf("print deps failed: (%v)", err)
53+
if err := printDeps(depManager); err != nil {
54+
return fmt.Errorf("print deps failed: %v", err)
5755
}
5856
return nil
5957
}
6058

61-
func printDeps(asFile bool) error {
62-
// Make sure the project has a dep manager file.
63-
mt, err := projutil.GetDepManagerType()
64-
if err != nil {
59+
func printDeps(depManager string) (err error) {
60+
// Use depManager if set. Fall back to the project's current dep manager
61+
// type if unset.
62+
mt := projutil.DepManagerType(depManager)
63+
if mt != "" {
64+
if mt != projutil.DepManagerDep && mt != projutil.DepManagerGoMod {
65+
return projutil.ErrInvalidDepManager(mt)
66+
}
67+
} else if mt, err = projutil.GetDepManagerType(); err != nil {
6568
return err
6669
}
6770
isDep := mt == projutil.DepManagerDep
@@ -71,19 +74,19 @@ func printDeps(asFile bool) error {
7174
switch {
7275
case projutil.IsOperatorAnsible():
7376
if isDep {
74-
return ansible.PrintDepGopkgTOML(asFile)
77+
return ansible.PrintDepGopkgTOML()
7578
}
76-
return ansible.PrintGoMod(asFile)
79+
return ansible.PrintGoMod()
7780
case projutil.IsOperatorHelm():
7881
if isDep {
79-
return helm.PrintDepGopkgTOML(asFile)
82+
return helm.PrintDepGopkgTOML()
8083
}
81-
return helm.PrintGoMod(asFile)
84+
return helm.PrintGoMod()
8285
case projutil.IsOperatorGo():
8386
if isDep {
84-
return scaffold.PrintDepGopkgTOML(asFile)
87+
return scaffold.PrintDepGopkgTOML()
8588
}
86-
return scaffold.PrintGoMod(asFile)
89+
return scaffold.PrintGoMod()
8790
}
8891

8992
return projutil.ErrUnknownOperatorType{}

doc/sdk-cli-reference.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ Prints the most recent Golang packages and versions required by operators. Print
9191

9292
### Flags
9393

94-
* `--as-file` - Print packages and versions in go.mod or Gopkg.toml format, depending on the dependency manager chosen when initializing or migrating a project.
94+
* `--dep-manager` string - Dependency manager file type to print (choices: "dep", "modules")
9595

9696
### Example
9797

9898
With dependency manager `dep`:
9999

100100
```console
101-
$ operator-sdk print-deps --as-file
101+
$ operator-sdk print-deps
102102
required = [
103103
"k8s.io/code-generator/cmd/deepcopy-gen",
104104
"k8s.io/code-generator/cmd/conversion-gen",
@@ -115,10 +115,10 @@ required = [
115115
...
116116
```
117117

118-
With dependency manager `modules`, i.e. go mod:
118+
With dependency manager Go `modules`:
119119

120120
```console
121-
$ operator-sdk print-deps --as-file
121+
$ operator-sdk print-deps
122122
module github.com/example-inc/memcached-operator
123123

124124
require (
@@ -560,7 +560,6 @@ $ operator-sdk up local --namespace "testing"
560560

561561
### Flags
562562

563-
* `--version` string - version of OLM resources to install, uninstall, or get status about (default: "latest")
564563
* `--timeout` duration - time to wait for the command to complete before failing (default: "2m")
565564

566565
### Available commands
@@ -577,42 +576,33 @@ then creating all of the necessary resources and waiting for them to become
577576
healthy. When the installation is complete, `olm install` outputs a status summary
578577
of all of the resources that were installed.
579578

579+
##### Flags
580+
581+
* `--version` string - version of OLM resources to install, uninstall, or get status about (default: "latest")
582+
580583
#### uninstall - Uninstalls Operator Lifecycle Manager
581584

582585
##### Use
583586

584587
The `operator-sdk alpha olm uninstall` command uninstalls OLM from a Kubernetes
585588
cluster based on the configured kubeconfig. It works by downloading OLM's
586-
release manifests at a specific version (default: `latest`), checking to see if
589+
release manifests at the version installed in the cluster, checking to see if
587590
any of those resources exist (if none exist, it aborts with an error since OLM
588591
is not installed), and then deletes each resource that is listed in the
589592
downloaded release manifests. It waits until all resources have been fully
590593
cleaned up before returning.
591594

592-
**NOTE**: It is important to use `--version` with the version number that
593-
corresponds to the version that you installed with `olm install`. Not specifying
594-
the version (or using an incorrect version) may cause some resources not be
595-
cleaned up. This can occur if OLM changes its release manifest resources from
596-
one version of OLM to the next.
597-
598595
#### status - Get status of the Operator Lifecycle Manager installation
599596

600597
##### Use
601598

602599
The `operator-sdk alpha olm status` command gets the status of the OLM
603600
installation in a Kubernetes cluster based on the configured kubeconfig. It
604-
works by downloading OLM's release manifests at a specific version (default:
605-
`latest`), checking to see if any of those resources exist (if none exist, it
601+
works by downloading OLM's release manifests at the version installed in the
602+
cluster, checking to see if any of those resources exist (if none exist, it
606603
aborts with an error since OLM is not installed), and printing a summary of the
607604
status of each of those resources as they exist in the cluster.
608605

609-
**NOTE**: It is important to use `--version` with the version number that
610-
corresponds to the version that you installed with `olm install`. Not specifying
611-
the version (or using an incorrect version) may cause some resources to be
612-
missing from the summary and others to be listed as "not found". This can occur
613-
if OLM changes its release manifest resources from one version of OLM to the
614-
next.
615-
616606
[utility_link]: https://github.com/operator-framework/operator-sdk/blob/89bf021063d18b6769bdc551ed08fc37027939d5/pkg/util/k8sutil/k8sutil.go#L140
617607
[k8s-code-generator]: https://github.com/kubernetes/code-generator
618608
[openapi-code-generator]: https://github.com/kubernetes/kube-openapi

doc/user-guide.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,20 @@ err := c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequest
163163
})
164164
```
165165

166-
**// TODO:** Doc on eventhandler, arbitrary mapping between watched and reconciled resource.
166+
#### Controller configurations
167+
168+
There are a number of useful configurations that can be made when initialzing a controller and declaring the watch parameters. For more details on these configurations consult the upstream [controller godocs][controller_godocs].
169+
170+
- Set the max number of concurrent Reconciles for the controller via the [`MaxConcurrentReconciles`][controller_options] option. Defaults to 1.
171+
```Go
172+
_, err := controller.New("memcached-controller", mgr, controller.Options{
173+
MaxConcurrentReconciles: 2,
174+
...
175+
})
176+
```
177+
- Filter watch events using [predicates][event_filtering]
178+
- Choose the type of [EventHandler][event_handler_godocs] to change how a watch event will translate to reconcile requests for the reconcile loop. For operator relationships that are more complex than primary and secondary resources, the [`EnqueueRequestsFromMapFunc`][enqueue_requests_from_map_func] handler can be used to transform a watch event into an arbitrary set of reconcile requests.
167179

168-
**// TODO:** Doc on configuring a Controller: number of workers, predicates, watching channels,
169180

170181
### Reconcile loop
171182

@@ -614,6 +625,11 @@ func main() {
614625

615626
When the operator is not running in a cluster, the Manager will return an error on starting since it can't detect the operator's namespace in order to create the configmap for leader election. You can override this namespace by setting the Manager's `LeaderElectionNamespace` option.
616627

628+
[enqueue_requests_from_map_func]: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/handler#EnqueueRequestsFromMapFunc
629+
[event_handler_godocs]: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/handler#hdr-EventHandlers
630+
[event_filtering]:./user/event-filtering.md
631+
[controller_options]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/controller#Options
632+
[controller_godocs]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/controller
617633
[operator_scope]:./operator-scope.md
618634
[install_guide]: ./user/install-operator-sdk.md
619635
[pod_eviction_timeout]: https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/#options

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
cloud.google.com/go v0.37.2 // indirect
77
contrib.go.opencensus.io/exporter/ocagent v0.4.11 // indirect
88
github.com/Azure/go-autorest v11.7.0+incompatible // indirect
9-
github.com/BurntSushi/toml v0.3.1
109
github.com/DATA-DOG/go-sqlmock v1.3.3 // indirect
1110
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect
1211
github.com/Masterminds/goutils v1.1.0 // indirect

hack/tests/alpha-olm-subcommands.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,35 @@ set -ex
55

66
test_version() {
77
local version="$1"
8+
# If version is "latest", run without --version flag
9+
local ver_flag="--version=${version}"
10+
if [[ "$version" == "latest" ]]; then
11+
ver_flag=""
12+
fi
813

914
# Status should fail with OLM not installed
10-
commandoutput=$(operator-sdk alpha olm status --version=${version} 2>&1 || true)
11-
echo $commandoutput | grep -F "Failed to get OLM status for version \\\"${version}\\\": no existing installation found"
15+
commandoutput=$(operator-sdk alpha olm status 2>&1 || true)
16+
echo $commandoutput | grep -F "Failed to get OLM status: no existing installation found"
1217

1318
# Uninstall should fail with OLM not installed
14-
commandoutput=$(operator-sdk alpha olm uninstall --version=${version} 2>&1 || true)
15-
echo $commandoutput | grep -F "Failed to uninstall OLM version \\\"${version}\\\": no existing installation found"
19+
commandoutput=$(operator-sdk alpha olm uninstall 2>&1 || true)
20+
echo $commandoutput | grep -F "Failed to uninstall OLM: no existing installation found"
1621

1722
# Install should succeed with nothing installed
18-
commandoutput=$(operator-sdk alpha olm install --version=${version} 2>&1)
23+
commandoutput=$(operator-sdk alpha olm install $ver_flag 2>&1)
1924
echo $commandoutput | grep -F "Successfully installed OLM version \\\"${version}\\\""
2025

2126
# Install should fail with OLM Installed
22-
commandoutput=$(operator-sdk alpha olm install --version=${version} 2>&1 || true)
27+
commandoutput=$(operator-sdk alpha olm install $ver_flag 2>&1 || true)
2328
echo $commandoutput | grep -F "Failed to install OLM version \\\"${version}\\\": detected existing OLM resources: OLM must be completely uninstalled before installation"
2429

2530
# Status should succeed with OLM installed
26-
# If version is "latest", also run without --version flag
27-
if [[ "$version" == "latest" ]]; then
28-
commandoutput=$(operator-sdk alpha olm status 2>&1)
29-
echo $commandoutput | grep -F "Successfully got OLM status for version \\\"${version}\\\""
30-
fi
31-
32-
commandoutput=$(operator-sdk alpha olm status --version=${version} 2>&1)
33-
echo $commandoutput | grep -F "Successfully got OLM status for version \\\"${version}\\\""
31+
commandoutput=$(operator-sdk alpha olm status 2>&1)
32+
echo $commandoutput | grep -F "Successfully got OLM status"
3433

3534
# Uninstall should succeed with OLM installed
36-
commandoutput=$(operator-sdk alpha olm uninstall --version=${version} 2>&1)
37-
echo $commandoutput | grep -F "Successfully uninstalled OLM version \\\"${version}\\\""
35+
commandoutput=$(operator-sdk alpha olm uninstall 2>&1)
36+
echo $commandoutput | grep -F "Successfully uninstalled OLM"
3837
}
3938

4039
test_version "latest"

0 commit comments

Comments
 (0)