Skip to content

Commit 550cb3e

Browse files
committed
Merge branch 'master' into modularize-scorecard
2 parents 926b8ee + 683d3b2 commit 550cb3e

File tree

15 files changed

+85
-70
lines changed

15 files changed

+85
-70
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
### Added
44

55
- By default the controller-runtime metrics are exposed on port 8383. This is done as part of the scaffold in the main.go file, the port can be adjusted by modifying the `metricsPort` variable. [#786](https://github.com/operator-framework/operator-sdk/pull/786)
6+
- A new command [`operator-sdk olm-catalog`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#olm-catalog) to be used as a parent for SDK subcommands generating code related to Operator Lifecycle Manager (OLM) Catalog integration, and subcommand [`operator-sdk olm-catalog gen-csv`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#gen-csv) which generates a Cluster Service Version for an operator so the OLM can deploy the operator in a cluster. ([#673](https://github.com/operator-framework/operator-sdk/pull/673))
7+
- Helm-based operators have leader election turned on by default. When upgrading, add environment variable `POD_NAME` to your operator's Deployment using the Kubernetes downward API. To see an example, run `operator-sdk new --type=helm ...` and see file `deploy/operator.yaml`. [#1000](https://github.com/operator-framework/operator-sdk/pull/1000)
68

79
### Changed
810

Gopkg.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
[[constraint]]
4646
name = "github.com/operator-framework/operator-lifecycle-manager"
47-
revision = "7ba3268c94bb247da0e5f3e1e625b5347ad9f1fb"
47+
revision = "5eb7ae5bdb7ac36a26d6e34e5d0ec07be128927f"
4848

4949
[[override]]
5050
name = "k8s.io/kube-aggregator"

README.md

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

33
[![Build Status](https://travis-ci.org/operator-framework/operator-sdk.svg?branch=master)](https://travis-ci.org/operator-framework/operator-sdk)
44

5-
### Project Status: alpha
6-
7-
The project is currently alpha which means that there are still new features and APIs planned that will be added in the future. Due to this breaking changes may still happen.
8-
9-
**Note:** The core APIs provided by the [controller-runtime][controller_runtime] will most likely stay unchanged however the expectation is that any breaking changes should be relatively minor and easier to handle than the changes from SDK `v0.0.7` to `v0.1.0`.
10-
11-
See the [proposal docs][proposals_docs] and issues for ongoing or planned work.
12-
135
## Overview
146

157
This project is a component of the [Operator Framework][of-home], an open source toolkit to manage Kubernetes native applications, called Operators, in an effective, automated, and scalable way. Read more in the [introduction blog post][of-blog].
@@ -155,6 +147,8 @@ To explore any operator samples built using the operator-sdk, see the [operator-
155147

156148
See [CONTRIBUTING][contrib] for details on submitting patches and the contribution workflow.
157149

150+
See the [proposal docs][proposals_docs] and issues for ongoing or planned work.
151+
158152
## Reporting bugs
159153

160154
See [reporting bugs][bug_guide] for details about reporting any issues.

commands/operator-sdk/cmd/scorecard/olm_tests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package scorecard
1717
import (
1818
"context"
1919

20-
olmAPI "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
20+
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
2121
"k8s.io/apimachinery/pkg/types"
2222
)
2323

@@ -63,7 +63,7 @@ func statusDescriptors(test *Test, vars ScorecardVars) error {
6363
}
6464
statusBlock := vars.crObj.Object["status"].(map[string]interface{})
6565
score.maximumPoints = len(statusBlock)
66-
var crd *olmAPI.CRDDescription
66+
var crd *olmapiv1alpha1.CRDDescription
6767
for _, owned := range vars.csvObj.Spec.CustomResourceDefinitions.Owned {
6868
if owned.Kind == vars.crObj.GetKind() {
6969
crd = &owned
@@ -102,7 +102,7 @@ func specDescriptors(test *Test, vars ScorecardVars) error {
102102
}
103103
specBlock := vars.crObj.Object["spec"].(map[string]interface{})
104104
score.maximumPoints = len(specBlock)
105-
var crd *olmAPI.CRDDescription
105+
var crd *olmapiv1alpha1.CRDDescription
106106
for _, owned := range vars.csvObj.Spec.CustomResourceDefinitions.Owned {
107107
if owned.Kind == vars.crObj.GetKind() {
108108
crd = &owned

commands/operator-sdk/cmd/scorecard/scorecard.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
k8sInternal "github.com/operator-framework/operator-sdk/internal/util/k8sutil"
2424
"github.com/operator-framework/operator-sdk/internal/util/yamlutil"
2525

26-
olmApi "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
26+
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
2727
log "github.com/sirupsen/logrus"
2828
"github.com/spf13/cobra"
2929
v1 "k8s.io/api/core/v1"
@@ -80,8 +80,6 @@ var (
8080
const scorecardPodName = "operator-scorecard-test"
8181

8282
func ScorecardTests(cmd *cobra.Command, args []string) error {
83-
// in main.go, we catch and print errors, so we don't want cobra to print the error itself
84-
cmd.SilenceErrors = true
8583
if !SCConf.BasicTests && !SCConf.OLMTests {
8684
return errors.New("at least one test type is required")
8785
}
@@ -130,7 +128,7 @@ func ScorecardTests(cmd *cobra.Command, args []string) error {
130128
var err error
131129
kubeconfig, SCConf.Namespace, err = k8sInternal.GetKubeconfigAndNamespace(SCConf.KubeconfigPath)
132130
if err != nil {
133-
return err
131+
return fmt.Errorf("failed to build the kubeconfig: %v", err)
134132
}
135133
scheme := runtime.NewScheme()
136134
// scheme for client go
@@ -142,7 +140,7 @@ func ScorecardTests(cmd *cobra.Command, args []string) error {
142140
return fmt.Errorf("failed to add failed to add extensions api scheme to client: (%v)", err)
143141
}
144142
// olm api (CS
145-
if err := olmApi.AddToScheme(scheme); err != nil {
143+
if err := olmapiv1alpha1.AddToScheme(scheme); err != nil {
146144
return fmt.Errorf("failed to add failed to add oml api scheme (CSVs) to client: (%v)", err)
147145
}
148146
dynamicDecoder = serializer.NewCodecFactory(scheme).UniversalDeserializer()
@@ -196,9 +194,9 @@ func ScorecardTests(cmd *cobra.Command, args []string) error {
196194
if err != nil {
197195
return err
198196
}
199-
csv := &olmApi.ClusterServiceVersion{}
197+
csv := &olmapiv1alpha1.ClusterServiceVersion{}
200198
switch o := rawCSV.(type) {
201-
case *olmApi.ClusterServiceVersion:
199+
case *olmapiv1alpha1.ClusterServiceVersion:
202200
csv = o
203201
default:
204202
return fmt.Errorf("provided yaml file not of ClusterServiceVersion type")

commands/operator-sdk/cmd/scorecard/test_definitions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package scorecard
1717
import (
1818
"fmt"
1919

20-
olmAPI "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
20+
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
2121
v1 "k8s.io/api/core/v1"
2222
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2323
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,7 +29,7 @@ import (
2929
type ScorecardVars struct {
3030
client *client.Client
3131
crObj *unstructured.Unstructured
32-
csvObj *olmAPI.ClusterServiceVersion
32+
csvObj *olmapiv1alpha1.ClusterServiceVersion
3333
proxyPod *v1.Pod
3434
timeout int
3535
retryInterval int

doc/user/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ import (
269269
func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, error) {
270270
...
271271

272-
mem := &cachev1alpha.Memcached{}
272+
mem := &cachev1alpha1.Memcached{}
273273
err := r.client.Get(context.TODO(), request.NamespacedName, mem)
274274

275275
...

pkg/helm/run.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package helm
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"os"
2021
"runtime"
@@ -24,6 +25,7 @@ import (
2425
hoflags "github.com/operator-framework/operator-sdk/pkg/helm/flags"
2526
"github.com/operator-framework/operator-sdk/pkg/helm/release"
2627
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
28+
"github.com/operator-framework/operator-sdk/pkg/leader"
2729
sdkVersion "github.com/operator-framework/operator-sdk/version"
2830

2931
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -99,6 +101,18 @@ func Run(flags *hoflags.HelmOperatorFlags) error {
99101
}
100102
}
101103

104+
operatorName, err := k8sutil.GetOperatorName()
105+
if err != nil {
106+
log.Error(err, "Failed to get operator name")
107+
return err
108+
}
109+
// Become the leader before proceeding
110+
err = leader.Become(context.TODO(), operatorName+"-lock")
111+
if err != nil {
112+
log.Error(err, "Failed to become leader.")
113+
return err
114+
}
115+
102116
// Start the Cmd
103117
if err = mgr.Start(signals.SetupSignalHandler()); err != nil {
104118
log.Error(err, "Manager exited non-zero.")

pkg/scaffold/cr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (s *Cr) GetInput() (input.Input, error) {
3838
s.Resource.LowerKind)
3939
s.Path = filepath.Join(CrdsDir, fileName)
4040
}
41+
s.IfExistsAction = input.Skip
4142
s.TemplateBody = crTemplate
4243
return s.Input, nil
4344
}

pkg/scaffold/crd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (s *Crd) GetInput() (input.Input, error) {
3838
s.Resource.LowerKind)
3939
s.Path = filepath.Join(CrdsDir, fileName)
4040
}
41+
s.IfExistsAction = input.Skip
4142
s.TemplateBody = crdTemplate
4243
return s.Input, nil
4344
}

pkg/scaffold/helm/operator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ spec:
6969
fieldRef:
7070
fieldPath: metadata.namespace
7171
{{- end}}
72+
- name: POD_NAME
73+
valueFrom:
74+
fieldRef:
75+
fieldPath: metadata.name
7276
- name: OPERATOR_NAME
7377
value: "{{.ProjectName}}"
7478
`

pkg/scaffold/olm-catalog/csv.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
"github.com/coreos/go-semver/semver"
3333
"github.com/ghodss/yaml"
34-
olmApi "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
34+
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
3535
log "github.com/sirupsen/logrus"
3636
)
3737

@@ -68,15 +68,15 @@ func (s *CSV) GetInput() (input.Input, error) {
6868
}
6969

7070
// CustomRender allows a CSV to be written by marshalling
71-
// olmApi.ClusterServiceVersion instead of writing to a template.
71+
// olmapiv1alpha1.ClusterServiceVersion instead of writing to a template.
7272
func (s *CSV) CustomRender() ([]byte, error) {
7373
// Get current CSV to update.
7474
csv, exists, err := getCurrentCSVIfExists(s.Path)
7575
if err != nil {
7676
return nil, err
7777
}
7878
if !exists {
79-
csv = &olmApi.ClusterServiceVersion{}
79+
csv = &olmapiv1alpha1.ClusterServiceVersion{}
8080
s.initCSVFields(csv)
8181
}
8282

@@ -111,7 +111,7 @@ func (s *CSV) CustomRender() ([]byte, error) {
111111
return yaml.Marshal(&cu)
112112
}
113113

114-
func getCurrentCSVIfExists(csvPath string) (*olmApi.ClusterServiceVersion, bool, error) {
114+
func getCurrentCSVIfExists(csvPath string) (*olmapiv1alpha1.ClusterServiceVersion, bool, error) {
115115
if _, err := os.Stat(csvPath); err != nil && os.IsNotExist(err) {
116116
return nil, false, nil
117117
}
@@ -124,7 +124,7 @@ func getCurrentCSVIfExists(csvPath string) (*olmApi.ClusterServiceVersion, bool,
124124
return nil, false, nil
125125
}
126126

127-
csv := &olmApi.ClusterServiceVersion{}
127+
csv := &olmapiv1alpha1.ClusterServiceVersion{}
128128
if err := yaml.Unmarshal(csvBytes, csv); err != nil {
129129
return nil, false, err
130130
}
@@ -173,10 +173,10 @@ func getDisplayName(name string) string {
173173

174174
// initCSVFields initializes all csv fields that should be populated by a user
175175
// with sane defaults. initCSVFields should only be called for new csv's.
176-
func (s *CSV) initCSVFields(csv *olmApi.ClusterServiceVersion) {
176+
func (s *CSV) initCSVFields(csv *olmapiv1alpha1.ClusterServiceVersion) {
177177
// Metadata
178-
csv.TypeMeta.APIVersion = olmApi.ClusterServiceVersionAPIVersion
179-
csv.TypeMeta.Kind = olmApi.ClusterServiceVersionKind
178+
csv.TypeMeta.APIVersion = olmapiv1alpha1.ClusterServiceVersionAPIVersion
179+
csv.TypeMeta.Kind = olmapiv1alpha1.ClusterServiceVersionKind
180180
csv.SetName(getCSVName(strings.ToLower(s.ProjectName), s.CSVVersion))
181181
csv.SetNamespace("placeholder")
182182

@@ -185,21 +185,21 @@ func (s *CSV) initCSVFields(csv *olmApi.ClusterServiceVersion) {
185185
csv.Spec.DisplayName = getDisplayName(s.ProjectName)
186186
csv.Spec.Description = "Placeholder description"
187187
csv.Spec.Maturity = "alpha"
188-
csv.Spec.Provider = olmApi.AppLink{}
189-
csv.Spec.Maintainers = make([]olmApi.Maintainer, 0)
190-
csv.Spec.Links = make([]olmApi.AppLink, 0)
188+
csv.Spec.Provider = olmapiv1alpha1.AppLink{}
189+
csv.Spec.Maintainers = make([]olmapiv1alpha1.Maintainer, 0)
190+
csv.Spec.Links = make([]olmapiv1alpha1.AppLink, 0)
191191
csv.SetLabels(make(map[string]string))
192192
}
193193

194194
// TODO: validate that all fields from files are populated as expected
195195
// ex. add `resources` to a CRD
196196

197-
func getEmptyRequiredCSVFields(csv *olmApi.ClusterServiceVersion) (fields []string) {
197+
func getEmptyRequiredCSVFields(csv *olmapiv1alpha1.ClusterServiceVersion) (fields []string) {
198198
// Metadata
199-
if csv.TypeMeta.APIVersion != olmApi.ClusterServiceVersionAPIVersion {
199+
if csv.TypeMeta.APIVersion != olmapiv1alpha1.ClusterServiceVersionAPIVersion {
200200
fields = append(fields, "apiVersion")
201201
}
202-
if csv.TypeMeta.Kind != olmApi.ClusterServiceVersionKind {
202+
if csv.TypeMeta.Kind != olmapiv1alpha1.ClusterServiceVersionKind {
203203
fields = append(fields, "kind")
204204
}
205205
if csv.ObjectMeta.Name == "" {
@@ -221,7 +221,7 @@ func getEmptyRequiredCSVFields(csv *olmApi.ClusterServiceVersion) (fields []stri
221221
if len(csv.Spec.Maintainers) == 0 {
222222
fields = append(fields, "spec.maintainers")
223223
}
224-
if csv.Spec.Provider == (olmApi.AppLink{}) {
224+
if csv.Spec.Provider == (olmapiv1alpha1.AppLink{}) {
225225
fields = append(fields, "spec.provider")
226226
}
227227
if len(csv.Spec.Labels) == 0 {
@@ -242,7 +242,7 @@ func joinFields(fields []string) string {
242242
// updateCSVVersions updates csv's version and data involving the version,
243243
// ex. ObjectMeta.Name, and place the old version in the `replaces` object,
244244
// if there is an old version to replace.
245-
func (s *CSV) updateCSVVersions(csv *olmApi.ClusterServiceVersion) error {
245+
func (s *CSV) updateCSVVersions(csv *olmapiv1alpha1.ClusterServiceVersion) error {
246246

247247
// Old csv version to replace, and updated csv version.
248248
oldVer, newVer := csv.Spec.Version.String(), s.CSVVersion
@@ -292,7 +292,7 @@ func replaceAllBytes(v interface{}, old, new []byte) error {
292292

293293
// updateCSVFromManifestFiles gathers relevant data from generated and
294294
// user-defined manifests and updates csv.
295-
func (s *CSV) updateCSVFromManifestFiles(cfg *CSVConfig, csv *olmApi.ClusterServiceVersion) error {
295+
func (s *CSV) updateCSVFromManifestFiles(cfg *CSVConfig, csv *olmapiv1alpha1.ClusterServiceVersion) error {
296296
store := NewUpdaterStore()
297297
for _, f := range append(cfg.CRDCRPaths, cfg.OperatorPath, cfg.RolePath) {
298298
yamlData, err := ioutil.ReadFile(f)

pkg/scaffold/olm-catalog/csv_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828

2929
"github.com/coreos/go-semver/semver"
3030
"github.com/ghodss/yaml"
31-
olmApi "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
32-
olmInstall "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
31+
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
32+
olminstall "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
3333
)
3434

3535
const testDataDir = "testdata"
@@ -77,7 +77,7 @@ func TestUpdateVersion(t *testing.T) {
7777
if err != nil {
7878
t.Fatal(err)
7979
}
80-
csv := &olmApi.ClusterServiceVersion{}
80+
csv := &olmapiv1alpha1.ClusterServiceVersion{}
8181
if err := yaml.Unmarshal(csvExpBytes, csv); err != nil {
8282
t.Fatal(err)
8383
}
@@ -102,12 +102,12 @@ func TestUpdateVersion(t *testing.T) {
102102
t.Errorf("Wanted csv name %s, got %s", wantedName, csv.ObjectMeta.Name)
103103
}
104104

105-
var resolver *olmInstall.StrategyResolver
105+
var resolver *olminstall.StrategyResolver
106106
stratInterface, err := resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
107107
if err != nil {
108108
t.Fatal(err)
109109
}
110-
strat, ok := stratInterface.(*olmInstall.StrategyDetailsDeployment)
110+
strat, ok := stratInterface.(*olminstall.StrategyDetailsDeployment)
111111
if !ok {
112112
t.Fatalf("Strategy of type %T was not StrategyDetailsDeployment", stratInterface)
113113
}

0 commit comments

Comments
 (0)