Skip to content

Commit 0918feb

Browse files
committed
Merge branch 'master' into test-no-setup
2 parents 5182ece + c6b5473 commit 0918feb

File tree

19 files changed

+427
-107
lines changed

19 files changed

+427
-107
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
install: true
3333
after_success: echo 'Markdown links are correct'
3434
after_failure: echo 'Incorrect markdown link detected'
35-
script: ./hack/ci/marker
35+
script: ./hack/ci/marker --root=./doc
3636

3737
install:
3838
- curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## Unreleased
2+
3+
### Changed
4+
5+
- The SDK now uses logr as the default logger to unify the logging output with the controller-runtime logs. Users can still use a logger of their own choice. See the [logging doc](https://github.com/operator-framework/operator-sdk/blob/master/doc/user/logging.md) on how the SDK initializes and uses logr.
6+
7+
### Bug fixes
8+
9+
- Make operator-sdk command work with composed GOPATH ([#676](https://github.com/operator-framework/operator-sdk/pull/676))
10+
111
## v0.1.1
212

313
### Bug fixes

Gopkg.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2018 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 cmd
16+
17+
import (
18+
"github.com/operator-framework/operator-sdk/pkg/scaffold"
19+
20+
log "github.com/sirupsen/logrus"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
var asFile bool
25+
26+
func NewPrintDepsCmd() *cobra.Command {
27+
printDepsCmd := &cobra.Command{
28+
Use: "print-deps",
29+
Short: "Print Golang packages and versions required to run the operator",
30+
Long: `The operator-sdk print-deps command prints all Golang packages and versions expected
31+
by this version of the Operator SDK. Versions for these packages should match
32+
those in an operators' Gopkg.toml file.
33+
34+
print-deps prints in columnar format by default. Use the --as-file flag to
35+
print in Gopkg.toml file format.
36+
`,
37+
Run: printDepsFunc,
38+
}
39+
40+
printDepsCmd.Flags().BoolVar(&asFile, "as-file", false, "Print dependencies in Gopkg.toml file format.")
41+
42+
return printDepsCmd
43+
}
44+
45+
func printDepsFunc(cmd *cobra.Command, args []string) {
46+
if len(args) != 0 {
47+
log.Fatal("print-deps command does not take any arguments")
48+
}
49+
if asFile {
50+
scaffold.PrintDepsAsFile()
51+
} else {
52+
if err := scaffold.PrintDeps(); err != nil {
53+
log.Fatalf("print deps: (%v)", err)
54+
}
55+
}
56+
}

commands/operator-sdk/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func NewRootCmd() *cobra.Command {
3434
cmd.AddCommand(NewUpCmd())
3535
cmd.AddCommand(NewCompletionCmd())
3636
cmd.AddCommand(NewTestCmd())
37+
cmd.AddCommand(NewPrintDepsCmd())
3738

3839
return cmd
3940
}

doc/sdk-cli-reference.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,17 @@ operator-sdk completion bash
8888
# ex: ts=4 sw=4 et filetype=sh
8989
```
9090

91+
## print-deps
92+
93+
Prints the most recent Golang packages and versions required by operators. Prints in columnar format by default.
94+
95+
### Flags
96+
97+
* `--as-file` Print packages and versions in Gopkg.toml format.
98+
9199
## generate
92100

93-
### k8s
101+
### k8s
94102

95103
Runs the Kubernetes [code-generators][k8s-code-generator] for all Custom Resource Definitions (CRD) apis under `pkg/apis/...`.
96104
Currently only runs `deepcopy-gen` to generate the required `DeepCopy()` functions for all custom resource types.

hack/ci/setup-minikube.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

pkg/sdk/metrics.go renamed to pkg/metrics/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package sdk
15+
package metrics
1616

1717
import (
1818
"context"

pkg/sdk/service-monitor.go renamed to pkg/metrics/service-monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package sdk
15+
package metrics
1616

1717
import (
1818
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"

pkg/ready/ready.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2018 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 ready
16+
17+
import (
18+
"os"
19+
)
20+
21+
const FileName = "/tmp/operator-sdk-ready"
22+
23+
// Ready holds state about whether the operator is ready and communicates that
24+
// to a Kubernetes readiness probe.
25+
type Ready interface {
26+
// Set ensures that future readiness probes will indicate that the operator
27+
// is ready.
28+
Set() error
29+
30+
// Unset ensures that future readiness probes will indicate that the
31+
// operator is not ready.
32+
Unset() error
33+
}
34+
35+
// NewFileReady returns a Ready that uses the presence of a file on disk to
36+
// communicate whether the operator is ready. The operator's Pod definition
37+
// should include a readinessProbe of "exec" type that calls
38+
// "stat /tmp/operator-sdk-ready".
39+
func NewFileReady() Ready {
40+
return fileReady{}
41+
}
42+
43+
type fileReady struct{}
44+
45+
// Set creates a file on disk whose presense can be used by a readiness probe
46+
// to determine that the operator is ready.
47+
func (r fileReady) Set() error {
48+
f, err := os.Create(FileName)
49+
if err != nil {
50+
return err
51+
}
52+
return f.Close()
53+
}
54+
55+
// Unset removes the file on disk that was created by Set().
56+
func (r fileReady) Unset() error {
57+
return os.Remove(FileName)
58+
}

pkg/ready/ready_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2018 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 ready
16+
17+
import (
18+
"os"
19+
"testing"
20+
)
21+
22+
func TestFileReady(t *testing.T) {
23+
r := NewFileReady()
24+
err := r.Set()
25+
if err != nil {
26+
t.Errorf("could not set ready file: %v", err)
27+
}
28+
29+
_, err = os.Stat(FileName)
30+
if err != nil {
31+
t.Errorf("did not find expected file at %s: %v", FileName, err)
32+
}
33+
34+
err = r.Unset()
35+
if err != nil {
36+
t.Errorf("could not unset ready file: %v", err)
37+
}
38+
39+
_, err = os.Stat(FileName)
40+
if err == nil {
41+
t.Errorf("file still exists at %s", FileName)
42+
}
43+
if !os.IsNotExist(err) {
44+
t.Errorf("error determining if file still exists at %s: %v", FileName, err)
45+
}
46+
}

pkg/scaffold/cmd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (s *Cmd) GetInput() (input.Input, error) {
3737
const cmdTmpl = `package main
3838
3939
import (
40+
"context"
4041
"flag"
4142
"fmt"
4243
"os"
@@ -46,6 +47,8 @@ import (
4647
"{{ .Repo }}/pkg/controller"
4748
4849
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
50+
"github.com/operator-framework/operator-sdk/pkg/leader"
51+
"github.com/operator-framework/operator-sdk/pkg/ready"
4952
sdkVersion "github.com/operator-framework/operator-sdk/version"
5053
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
5154
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -86,6 +89,17 @@ func main() {
8689
os.Exit(1)
8790
}
8891
92+
// Become the leader before proceeding
93+
leader.Become(context.TODO(), "{{ .ProjectName }}-lock")
94+
95+
r := ready.NewFileReady()
96+
err = r.Set()
97+
if err != nil {
98+
log.Error(err, "")
99+
os.Exit(1)
100+
}
101+
defer r.Unset()
102+
89103
// Create a new Cmd to provide shared dependencies and start components
90104
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
91105
if err != nil {

pkg/scaffold/cmd_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestCmd(t *testing.T) {
3636
const cmdExp = `package main
3737
3838
import (
39+
"context"
3940
"flag"
4041
"fmt"
4142
"os"
@@ -44,6 +45,8 @@ import (
4445
"github.com/example-inc/app-operator/pkg/apis"
4546
"github.com/example-inc/app-operator/pkg/controller"
4647
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
48+
"github.com/operator-framework/operator-sdk/pkg/leader"
49+
"github.com/operator-framework/operator-sdk/pkg/ready"
4750
sdkVersion "github.com/operator-framework/operator-sdk/version"
4851
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4952
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -84,6 +87,17 @@ func main() {
8487
os.Exit(1)
8588
}
8689
90+
// Become the leader before proceeding
91+
leader.Become(context.TODO(), "app-operator-lock")
92+
93+
r := ready.NewFileReady()
94+
err = r.Set()
95+
if err != nil {
96+
log.Error(err, "")
97+
os.Exit(1)
98+
}
99+
defer r.Unset()
100+
87101
// Create a new Cmd to provide shared dependencies and start components
88102
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
89103
if err != nil {

0 commit comments

Comments
 (0)