Skip to content

Commit

Permalink
Merge branch 'master' into go-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Jul 2, 2019
2 parents b077269 + 5507e00 commit f61a6ef
Show file tree
Hide file tree
Showing 18 changed files with 908 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- Remove TypeMeta declaration from the implementation of the objects ([#1462](https://github.com/operator-framework/operator-sdk/pull/1462/))
- 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))
- 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))
- `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))
- `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))
- 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))
- `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))

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ test/unit:
$(Q)go test -count=1 -short ./pkg/...
$(Q)go test -count=1 -short ./internal/...

test/subcommand: test/subcommand/test-local test/subcommand/scorecard
test/subcommand: test/subcommand/test-local test/subcommand/scorecard test/subcommand/alpha-olm

test/subcommand/test-local:
./hack/tests/test-subcommand.sh

test/subcommand/scorecard:
./hack/tests/scorecard-subcommand.sh

test/subcommand/alpha-olm:
./hack/tests/alpha-olm-subcommands.sh

test/e2e: test/e2e/go test/e2e/ansible test/e2e/ansible-molecule test/e2e/helm

test/e2e/go:
Expand All @@ -136,7 +139,7 @@ test/e2e/helm: image/build/helm
test/markdown:
./hack/ci/marker --root=doc

.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
.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

image: image/build image/push

Expand Down
30 changes: 30 additions & 0 deletions cmd/operator-sdk/alpha/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 alpha

import (
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/olm"
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "alpha",
Short: "Run an alpha subcommand",
}

cmd.AddCommand(olm.NewCmd())
return cmd
}
32 changes: 32 additions & 0 deletions cmd/operator-sdk/alpha/olm/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 olm

import (
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "olm",
Short: "Manage the Operator Lifecycle Manager installation in your cluster",
}
cmd.AddCommand(
NewInstallCmd(),
NewUninstallCmd(),
NewStatusCmd(),
)
return cmd
}
39 changes: 39 additions & 0 deletions cmd/operator-sdk/alpha/olm/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 olm

import (
"github.com/operator-framework/operator-sdk/internal/olm"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func NewInstallCmd() *cobra.Command {
mgr := &olm.Manager{}
cmd := &cobra.Command{
Use: "install",
Short: "Install Operator Lifecycle Manager in your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
if err := mgr.Install(); err != nil {
log.Fatalf("Failed to install OLM version %q: %s", mgr.Version, err)
}
return nil
},
}

mgr.AddToFlagSet(cmd.Flags())
return cmd
}
39 changes: 39 additions & 0 deletions cmd/operator-sdk/alpha/olm/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 olm

import (
"github.com/operator-framework/operator-sdk/internal/olm"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func NewStatusCmd() *cobra.Command {
mgr := olm.Manager{}
cmd := &cobra.Command{
Use: "status",
Short: "Get the status of the Operator Lifecycle Manager installation in your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
if err := mgr.Status(); err != nil {
log.Fatalf("Failed to get OLM status for version %q: %s", mgr.Version, err)
}
return nil
},
}

mgr.AddToFlagSet(cmd.Flags())
return cmd
}
39 changes: 39 additions & 0 deletions cmd/operator-sdk/alpha/olm/uninstall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 olm

import (
"github.com/operator-framework/operator-sdk/internal/olm"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func NewUninstallCmd() *cobra.Command {
mgr := olm.Manager{}
cmd := &cobra.Command{
Use: "uninstall",
Short: "Uninstall Operator Lifecycle Manager from your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
if err := mgr.Uninstall(); err != nil {
log.Fatalf("Failed to uninstall OLM version %q: %s", mgr.Version, err)
}
return nil
},
}

mgr.AddToFlagSet(cmd.Flags())
return cmd
}
16 changes: 9 additions & 7 deletions cmd/operator-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
Expand Down Expand Up @@ -61,18 +62,19 @@ func main() {
},
}

root.AddCommand(new.NewCmd())
root.AddCommand(add.NewCmd())
root.AddCommand(alpha.NewCmd())
root.AddCommand(build.NewCmd())
root.AddCommand(generate.NewCmd())
root.AddCommand(up.NewCmd())
root.AddCommand(completion.NewCmd())
root.AddCommand(test.NewCmd())
root.AddCommand(scorecard.NewCmd())
root.AddCommand(printdeps.NewCmd())
root.AddCommand(generate.NewCmd())
root.AddCommand(migrate.NewCmd())
root.AddCommand(run.NewCmd())
root.AddCommand(new.NewCmd())
root.AddCommand(olmcatalog.NewCmd())
root.AddCommand(printdeps.NewCmd())
root.AddCommand(run.NewCmd())
root.AddCommand(scorecard.NewCmd())
root.AddCommand(test.NewCmd())
root.AddCommand(up.NewCmd())
root.AddCommand(version.NewCmd())

root.PersistentFlags().Bool(flags.VerboseOpt, false, "Enable verbose logging")
Expand Down
57 changes: 57 additions & 0 deletions doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,63 @@ $ operator-sdk up local --namespace "testing"

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

## alpha olm

### Flags

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

### Available commands

#### install - Installs Operator Lifecycle Manager

##### Use

The `operator-sdk alpha olm install` command installs OLM in a Kubernetes cluster
based on the configured kubeconfig. It works by downloading OLM's release
manifests at a specific version (default: `latest`), checking to see if any of
those resources already exist in the cluster (and aborting if they do), and
then creating all of the necessary resources and waiting for them to become
healthy. When the installation is complete, `olm install` outputs a status summary
of all of the resources that were installed.

#### uninstall - Uninstalls Operator Lifecycle Manager

##### Use

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

**NOTE**: It is important to use `--version` with the version number that
corresponds to the version that you installed with `olm install`. Not specifying
the version (or using an incorrect version) may cause some resources not be
cleaned up. This can occur if OLM changes its release manifest resources from
one version of OLM to the next.

#### status - Get status of the Operator Lifecycle Manager installation

##### Use

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

**NOTE**: It is important to use `--version` with the version number that
corresponds to the version that you installed with `olm install`. Not specifying
the version (or using an incorrect version) may cause some resources to be
missing from the summary and others to be listed as "not found". This can occur
if OLM changes its release manifest resources from one version of OLM to the
next.

[utility_link]: https://github.com/operator-framework/operator-sdk/blob/89bf021063d18b6769bdc551ed08fc37027939d5/pkg/util/k8sutil/k8sutil.go#L140
[k8s-code-generator]: https://github.com/kubernetes/code-generator
[openapi-code-generator]: https://github.com/kubernetes/kube-openapi
Expand Down
4 changes: 2 additions & 2 deletions doc/user/metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### General metrics

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.
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.

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.

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

// Create Service object to expose the metrics port.
_, err = metrics.CreateMetricsService(context.TODO(), servicePorts)
_, err = metrics.CreateMetricsService(context.TODO(), cfg, servicePorts)
if err != nil {
// handle error
}
Expand Down
41 changes: 41 additions & 0 deletions hack/tests/alpha-olm-subcommands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -ex


test_version() {
local version="$1"

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

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

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

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

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

commandoutput=$(operator-sdk alpha olm status --version=${version} 2>&1)
echo $commandoutput | grep -F "Successfully got OLM status for version \\\"${version}\\\""

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

test_version "latest"
test_version "0.10.1"
Loading

0 comments on commit f61a6ef

Please sign in to comment.