Skip to content

Commit f61a6ef

Browse files
committed
Merge branch 'master' into go-mod
2 parents b077269 + 5507e00 commit f61a6ef

File tree

18 files changed

+908
-33
lines changed

18 files changed

+908
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Remove TypeMeta declaration from the implementation of the objects ([#1462](https://github.com/operator-framework/operator-sdk/pull/1462/))
2121
- Relaxed API version format check when parsing `pkg/apis` in code generators. API dir structures can now be of the format `pkg/apis/<group>/<anything>`, where `<anything>` was previously required to be in the Kubernetes version format, ex. `v1alpha1`. ([#1525](https://github.com/operator-framework/operator-sdk/pull/1525))
2222
- The SDK and operator projects will work outside of `$GOPATH/src` when using [Go modules](https://github.com/golang/go/wiki/Modules). ([#1475](https://github.com/operator-framework/operator-sdk/pull/1475))
23-
- `CreateMetricsService()` function from the metrics package accepts an array of ServicePort objects ([]v1.ServicePort) as input to create Service metrics. `CRPortName` constant is added to describe the string of custom resource port name. ([#1560](https://github.com/operator-framework/operator-sdk/pull/1560))
23+
- `CreateMetricsService()` function from the metrics package accepts a REST config (\*rest.Config) and an array of ServicePort objects ([]v1.ServicePort) as input to create Service metrics. `CRPortName` constant is added to describe the string of custom resource port name. ([#1560](https://github.com/operator-framework/operator-sdk/pull/1560) and [#1626](https://github.com/operator-framework/operator-sdk/pull/1626))
2424
- Changed the flag `--skip-git-init` to [`--git-init`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#new). This changes the default behavior of `operator-sdk new` to not initialize the new project directory as a git repository with `git init`. This behavior is now opt-in with `--git-init`. ([#1588](https://github.com/operator-framework/operator-sdk/pull/1588))
2525
- `operator-sdk new` will no longer create the initial commit for a new project, even with `--git-init=true`. ([#1588](https://github.com/operator-framework/operator-sdk/pull/1588))
2626

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ test/unit:
108108
$(Q)go test -count=1 -short ./pkg/...
109109
$(Q)go test -count=1 -short ./internal/...
110110

111-
test/subcommand: test/subcommand/test-local test/subcommand/scorecard
111+
test/subcommand: test/subcommand/test-local test/subcommand/scorecard test/subcommand/alpha-olm
112112

113113
test/subcommand/test-local:
114114
./hack/tests/test-subcommand.sh
115115

116116
test/subcommand/scorecard:
117117
./hack/tests/scorecard-subcommand.sh
118118

119+
test/subcommand/alpha-olm:
120+
./hack/tests/alpha-olm-subcommands.sh
121+
119122
test/e2e: test/e2e/go test/e2e/ansible test/e2e/ansible-molecule test/e2e/helm
120123

121124
test/e2e/go:
@@ -136,7 +139,7 @@ test/e2e/helm: image/build/helm
136139
test/markdown:
137140
./hack/ci/marker --root=doc
138141

139-
.PHONY: test test-ci test/sanity test/unit test/subcommand test/e2e test/e2e/go test/e2e/ansible test/e2e/ansible-molecule test/e2e/helm test/ci-go test/ci-ansible test/ci-helm test/markdown
142+
.PHONY: test test-ci test/sanity test/unit test/subcommand test/subcommand/test-local test/subcommand/scorecard test/subcommand/alpha-olm test/e2e test/e2e/go test/e2e/ansible test/e2e/ansible-molecule test/e2e/helm test/ci-go test/ci-ansible test/ci-helm test/markdown
140143

141144
image: image/build image/push
142145

cmd/operator-sdk/alpha/cmd.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019 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 alpha
16+
17+
import (
18+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/olm"
19+
"github.com/spf13/cobra"
20+
)
21+
22+
func NewCmd() *cobra.Command {
23+
cmd := &cobra.Command{
24+
Use: "alpha",
25+
Short: "Run an alpha subcommand",
26+
}
27+
28+
cmd.AddCommand(olm.NewCmd())
29+
return cmd
30+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2019 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 olm
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
)
20+
21+
func NewCmd() *cobra.Command {
22+
cmd := &cobra.Command{
23+
Use: "olm",
24+
Short: "Manage the Operator Lifecycle Manager installation in your cluster",
25+
}
26+
cmd.AddCommand(
27+
NewInstallCmd(),
28+
NewUninstallCmd(),
29+
NewStatusCmd(),
30+
)
31+
return cmd
32+
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019 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 olm
16+
17+
import (
18+
"github.com/operator-framework/operator-sdk/internal/olm"
19+
20+
log "github.com/sirupsen/logrus"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
func NewInstallCmd() *cobra.Command {
25+
mgr := &olm.Manager{}
26+
cmd := &cobra.Command{
27+
Use: "install",
28+
Short: "Install Operator Lifecycle Manager in your cluster",
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
if err := mgr.Install(); err != nil {
31+
log.Fatalf("Failed to install OLM version %q: %s", mgr.Version, err)
32+
}
33+
return nil
34+
},
35+
}
36+
37+
mgr.AddToFlagSet(cmd.Flags())
38+
return cmd
39+
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019 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 olm
16+
17+
import (
18+
"github.com/operator-framework/operator-sdk/internal/olm"
19+
20+
log "github.com/sirupsen/logrus"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
func NewStatusCmd() *cobra.Command {
25+
mgr := olm.Manager{}
26+
cmd := &cobra.Command{
27+
Use: "status",
28+
Short: "Get the status of the Operator Lifecycle Manager installation in your cluster",
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
if err := mgr.Status(); err != nil {
31+
log.Fatalf("Failed to get OLM status for version %q: %s", mgr.Version, err)
32+
}
33+
return nil
34+
},
35+
}
36+
37+
mgr.AddToFlagSet(cmd.Flags())
38+
return cmd
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019 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 olm
16+
17+
import (
18+
"github.com/operator-framework/operator-sdk/internal/olm"
19+
20+
log "github.com/sirupsen/logrus"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
func NewUninstallCmd() *cobra.Command {
25+
mgr := olm.Manager{}
26+
cmd := &cobra.Command{
27+
Use: "uninstall",
28+
Short: "Uninstall Operator Lifecycle Manager from your cluster",
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
if err := mgr.Uninstall(); err != nil {
31+
log.Fatalf("Failed to uninstall OLM version %q: %s", mgr.Version, err)
32+
}
33+
return nil
34+
},
35+
}
36+
37+
mgr.AddToFlagSet(cmd.Flags())
38+
return cmd
39+
}

cmd/operator-sdk/main.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
_ "k8s.io/client-go/plugin/pkg/client/auth"
2424

2525
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
26+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
2627
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
2728
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
2829
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
@@ -61,18 +62,19 @@ func main() {
6162
},
6263
}
6364

64-
root.AddCommand(new.NewCmd())
6565
root.AddCommand(add.NewCmd())
66+
root.AddCommand(alpha.NewCmd())
6667
root.AddCommand(build.NewCmd())
67-
root.AddCommand(generate.NewCmd())
68-
root.AddCommand(up.NewCmd())
6968
root.AddCommand(completion.NewCmd())
70-
root.AddCommand(test.NewCmd())
71-
root.AddCommand(scorecard.NewCmd())
72-
root.AddCommand(printdeps.NewCmd())
69+
root.AddCommand(generate.NewCmd())
7370
root.AddCommand(migrate.NewCmd())
74-
root.AddCommand(run.NewCmd())
71+
root.AddCommand(new.NewCmd())
7572
root.AddCommand(olmcatalog.NewCmd())
73+
root.AddCommand(printdeps.NewCmd())
74+
root.AddCommand(run.NewCmd())
75+
root.AddCommand(scorecard.NewCmd())
76+
root.AddCommand(test.NewCmd())
77+
root.AddCommand(up.NewCmd())
7678
root.AddCommand(version.NewCmd())
7779

7880
root.PersistentFlags().Bool(flags.VerboseOpt, false, "Enable verbose logging")

doc/sdk-cli-reference.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,63 @@ $ operator-sdk up local --namespace "testing"
555555

556556
* `-h, --help` - help for up
557557

558+
## alpha olm
559+
560+
### Flags
561+
562+
* `--version` string - version of OLM resources to install, uninstall, or get status about (default: "latest")
563+
* `--timeout` duration - time to wait for the command to complete before failing (default: "2m")
564+
565+
### Available commands
566+
567+
#### install - Installs Operator Lifecycle Manager
568+
569+
##### Use
570+
571+
The `operator-sdk alpha olm install` command installs OLM in a Kubernetes cluster
572+
based on the configured kubeconfig. It works by downloading OLM's release
573+
manifests at a specific version (default: `latest`), checking to see if any of
574+
those resources already exist in the cluster (and aborting if they do), and
575+
then creating all of the necessary resources and waiting for them to become
576+
healthy. When the installation is complete, `olm install` outputs a status summary
577+
of all of the resources that were installed.
578+
579+
#### uninstall - Uninstalls Operator Lifecycle Manager
580+
581+
##### Use
582+
583+
The `operator-sdk alpha olm uninstall` command uninstalls OLM from a Kubernetes
584+
cluster based on the configured kubeconfig. It works by downloading OLM's
585+
release manifests at a specific version (default: `latest`), checking to see if
586+
any of those resources exist (if none exist, it aborts with an error since OLM
587+
is not installed), and then deletes each resource that is listed in the
588+
downloaded release manifests. It waits until all resources have been fully
589+
cleaned up before returning.
590+
591+
**NOTE**: It is important to use `--version` with the version number that
592+
corresponds to the version that you installed with `olm install`. Not specifying
593+
the version (or using an incorrect version) may cause some resources not be
594+
cleaned up. This can occur if OLM changes its release manifest resources from
595+
one version of OLM to the next.
596+
597+
#### status - Get status of the Operator Lifecycle Manager installation
598+
599+
##### Use
600+
601+
The `operator-sdk alpha olm status` command gets the status of the OLM
602+
installation in a Kubernetes cluster based on the configured kubeconfig. It
603+
works by downloading OLM's release manifests at a specific version (default:
604+
`latest`), checking to see if any of those resources exist (if none exist, it
605+
aborts with an error since OLM is not installed), and printing a summary of the
606+
status of each of those resources as they exist in the cluster.
607+
608+
**NOTE**: It is important to use `--version` with the version number that
609+
corresponds to the version that you installed with `olm install`. Not specifying
610+
the version (or using an incorrect version) may cause some resources to be
611+
missing from the summary and others to be listed as "not found". This can occur
612+
if OLM changes its release manifest resources from one version of OLM to the
613+
next.
614+
558615
[utility_link]: https://github.com/operator-framework/operator-sdk/blob/89bf021063d18b6769bdc551ed08fc37027939d5/pkg/util/k8sutil/k8sutil.go#L140
559616
[k8s-code-generator]: https://github.com/kubernetes/code-generator
560617
[openapi-code-generator]: https://github.com/kubernetes/kube-openapi

doc/user/metrics/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### General metrics
88

9-
The `"CreateMetricsService(ctx context.Context, servicePorts []v1.ServicePort) (*v1.Service, error)` function exposes general metrics about the running program. These metrics are inherited from controller-runtime. To understand which metrics are exposed, read the metrics package doc of [controller-runtime][controller-metrics]. The `ExposeMetricsPort` function creates a [Service][service] object with the metrics port exposed, which can then be accessed by Prometheus. The Service object is [garbage collected][gc] when the leader pod's root owner is deleted.
9+
The `"CreateMetricsService(ctx context.Context, cfg *rest.Config, servicePorts []v1.ServicePort) (*v1.Service, error)` function exposes general metrics about the running program. These metrics are inherited from controller-runtime. To understand which metrics are exposed, read the metrics package doc of [controller-runtime][controller-metrics]. The `ExposeMetricsPort` function creates a [Service][service] object with the metrics port exposed, which can then be accessed by Prometheus. The Service object is [garbage collected][gc] when the leader pod's root owner is deleted.
1010

1111
By default, the metrics are served on `0.0.0.0:8383/metrics`. To modify the port the metrics are exposed on, change the `var metricsPort int32 = 8383` variable in the `cmd/manager/main.go` file of the generated operator.
1212

@@ -44,7 +44,7 @@ By default, the metrics are served on `0.0.0.0:8383/metrics`. To modify the port
4444
}
4545

4646
// Create Service object to expose the metrics port.
47-
_, err = metrics.CreateMetricsService(context.TODO(), servicePorts)
47+
_, err = metrics.CreateMetricsService(context.TODO(), cfg, servicePorts)
4848
if err != nil {
4949
// handle error
5050
}

hack/tests/alpha-olm-subcommands.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
6+
test_version() {
7+
local version="$1"
8+
9+
# 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"
12+
13+
# 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"
16+
17+
# Install should succeed with nothing installed
18+
commandoutput=$(operator-sdk alpha olm install --version=${version} 2>&1)
19+
echo $commandoutput | grep -F "Successfully installed OLM version \\\"${version}\\\""
20+
21+
# Install should fail with OLM Installed
22+
commandoutput=$(operator-sdk alpha olm install --version=${version} 2>&1 || true)
23+
echo $commandoutput | grep -F "Failed to install OLM version \\\"${version}\\\": detected existing OLM resources: OLM must be completely uninstalled before installation"
24+
25+
# 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}\\\""
34+
35+
# 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}\\\""
38+
}
39+
40+
test_version "latest"
41+
test_version "0.10.1"

0 commit comments

Comments
 (0)