Skip to content

Commit 25fa9e6

Browse files
authored
Merge branch 'operator-framework:master' into upgrade-opm-version
2 parents f76581b + 1979f73 commit 25fa9e6

File tree

96 files changed

+869
-754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+869
-754
lines changed

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ SHELL = /bin/bash
44
# This value must be updated to the release tag of the most recent release, a change that must
55
# occur in the release commit. IMAGE_VERSION will be removed once each subproject that uses this
66
# version is moved to a separate repo and release process.
7-
export IMAGE_VERSION = v1.10.0
7+
export IMAGE_VERSION = v1.11.0
88
# Build-time variables to inject into binaries
99
export SIMPLE_VERSION = $(shell (test "$(shell git describe)" = "$(shell git describe --abbrev=0)" && echo $(shell git describe)) || echo $(shell git describe --abbrev=0)+git)
1010
export GIT_VERSION = $(shell git describe --dirty --tags --always)
1111
export GIT_COMMIT = $(shell git rev-parse HEAD)
12+
export K8S_VERSION = 1.21
1213
# TODO: bump this to 1.21, after kubectl `--generator` flag is removed from e2e tests.
13-
export K8S_VERSION = 1.20.2
14+
export ENVTEST_K8S_VERSION = 1.20.2
1415

1516
# Build settings
1617
export TOOLS_DIR = tools/bin
@@ -146,11 +147,11 @@ e2e_targets := test-e2e $(e2e_tests)
146147
.PHONY: test-e2e-setup
147148
export KIND_CLUSTER := operator-sdk-e2e
148149

149-
export KUBEBUILDER_ASSETS = $(PWD)/$(shell go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && $(shell go env GOPATH)/bin/setup-envtest use $(K8S_VERSION) --bin-dir tools/bin/ -p path)
150+
export KUBEBUILDER_ASSETS = $(PWD)/$(shell go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && $(shell go env GOPATH)/bin/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir tools/bin/ -p path)
150151
test-e2e-setup: build
151152
$(SCRIPTS_DIR)/fetch kind 0.11.0
152-
$(SCRIPTS_DIR)/fetch kubectl $(K8S_VERSION) # Install kubectl AFTER envtest because envtest includes its own kubectl binary
153-
[[ "`$(TOOLS_DIR)/kind get clusters`" =~ "$(KIND_CLUSTER)" ]] || $(TOOLS_DIR)/kind create cluster --image="kindest/node:v$(K8S_VERSION)" --name $(KIND_CLUSTER)
153+
$(SCRIPTS_DIR)/fetch kubectl $(ENVTEST_K8S_VERSION) # Install kubectl AFTER envtest because envtest includes its own kubectl binary
154+
[[ "`$(TOOLS_DIR)/kind get clusters`" =~ "$(KIND_CLUSTER)" ]] || $(TOOLS_DIR)/kind create cluster --image="kindest/node:v$(ENVTEST_K8S_VERSION)" --name $(KIND_CLUSTER)
154155

155156
.PHONY: test-e2e-teardown
156157
test-e2e-teardown:
@@ -162,7 +163,7 @@ test-e2e-teardown:
162163
# Repeated rules are executed in the order they appear.
163164
$(e2e_targets):: test-e2e-setup image/scorecard-test
164165
test-e2e:: $(e2e_tests) ## Run e2e tests
165-
166+
166167
test-e2e-go:: image/custom-scorecard-tests ## Run Go e2e tests
167168
go test ./test/e2e/go -v -ginkgo.v
168169
test-e2e-ansible:: image/ansible-operator ## Run Ansible e2e tests

changelog/fragments/detect-request-ns.yaml

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

changelog/generated/v1.11.0.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## v1.11.0
2+
3+
### Additions
4+
5+
- (go/v3, ansible/v1, helm/v1) Added `containerPort` protocol field required for server-side apply in manifests. ([#4863](https://github.com/operator-framework/operator-sdk/pull/4863))
6+
- For helm based operators, added a predicate that filters resources based on selectors specified in `watches.yaml`. Only the resources that contain the labels specified by selectors will be reconciled. ([#4997](https://github.com/operator-framework/operator-sdk/pull/4997))
7+
- For helm-based operators, support go `text/template` expansion of override values. ([#5105](https://github.com/operator-framework/operator-sdk/pull/5105))
8+
9+
### Changes
10+
11+
- (go/v3) Fixed a bug in `make test` caused by incorrect envtest asset setup. ([#4863](https://github.com/operator-framework/operator-sdk/pull/4863))
12+
- (go/v3, ansible/v1, helm/v1) Increased resource limits for controller manager. ([#4863](https://github.com/operator-framework/operator-sdk/pull/4863))
13+
- Updated operator-framework dependency to 0.10.5. This specific update includes a fix for bundle validation when checking for invalid service accounts. ([#5119](https://github.com/operator-framework/operator-sdk/pull/5119))
14+
- For helm-based operators, reverted #5042 and #4937 which modified helm release equality comparison. ([#5097](https://github.com/operator-framework/operator-sdk/pull/5097))
15+
16+
### Bug Fixes
17+
18+
- (ansible/v1) Previously, when scaffolding an Ansible-based operator with both Roles and Playbooks, the roles imported by the playbook could not be found when running locally (`make run`). This change prepends the `ANSIBLE_ROLES_PATH` environment variable with the path to the local roles directory. ([#5118](https://github.com/operator-framework/operator-sdk/pull/5118))
19+
- For Ansible-based operators, if a request is sent without a body in the metadata it will now be extracted from the request URL and properly set owner references/dependent watches. ([#5064](https://github.com/operator-framework/operator-sdk/pull/5064))
20+
- In `generate bundle`, exclude ServiceAccounts already in a CSV from generated bundle. ([#5120](https://github.com/operator-framework/operator-sdk/pull/5120))

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ require (
66
github.com/blang/semver/v4 v4.0.0
77
github.com/fatih/structtag v1.1.0
88
github.com/go-logr/logr v0.4.0
9+
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
910
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
1011
github.com/kr/text v0.2.0
1112
github.com/markbates/inflect v1.0.4
1213
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
1314
github.com/onsi/ginkgo v1.16.4
1415
github.com/onsi/gomega v1.13.0
15-
github.com/operator-framework/api v0.10.2
16+
github.com/operator-framework/api v0.10.5
1617
github.com/operator-framework/java-operator-plugins v0.0.0-20210708174638-463fb91f3d5e
17-
github.com/operator-framework/operator-lib v0.5.0
18+
github.com/operator-framework/operator-lib v0.6.0
1819
github.com/operator-framework/operator-registry v1.17.4
1920
github.com/prometheus/client_golang v1.11.0
2021
github.com/prometheus/client_model v0.2.0
@@ -39,7 +40,7 @@ require (
3940
k8s.io/kubectl v0.21.0
4041
sigs.k8s.io/controller-runtime v0.9.2
4142
sigs.k8s.io/controller-tools v0.6.0
42-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210707171043-359e8aa70c2b
43+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210803185103-51e4a9aa5055
4344
sigs.k8s.io/yaml v1.2.0
4445
)
4546

go.sum

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
409409
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
410410
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
411411
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
412+
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
412413
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
413414
github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
414415
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
@@ -823,12 +824,12 @@ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh
823824
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
824825
github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY=
825826
github.com/operator-framework/api v0.10.0/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI=
826-
github.com/operator-framework/api v0.10.2 h1:fo8Bhyx1v46NdJIz2rUzfzNUpe1KDNPtVpHVpuxZnk0=
827-
github.com/operator-framework/api v0.10.2/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI=
827+
github.com/operator-framework/api v0.10.5 h1:/WvLKOPo8zZMyEmuW0kLC0PJBt4Xal8HZkFioKIxqTA=
828+
github.com/operator-framework/api v0.10.5/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI=
828829
github.com/operator-framework/java-operator-plugins v0.0.0-20210708174638-463fb91f3d5e h1:LMsT59IJqaLn7kD6DnZFy0IouRufXyJHTT+mXQrl9Ps=
829830
github.com/operator-framework/java-operator-plugins v0.0.0-20210708174638-463fb91f3d5e/go.mod h1:sGKGELFkUeRqElcyvyPC89bC76YnCL7MPMa13P0AQcw=
830-
github.com/operator-framework/operator-lib v0.5.0 h1:Jmhz/WjcstEyBBM9IFUiHEgKg5bd43uF4ej/ZY2S0rM=
831-
github.com/operator-framework/operator-lib v0.5.0/go.mod h1:33Skl0vjauYx3nAS+cSFbHNkX8do7weQ6s5siIV/w1E=
831+
github.com/operator-framework/operator-lib v0.6.0 h1:srZoTL8P7OZUOovMkQkd4vwIbFzFNW413R/6V9N9rz4=
832+
github.com/operator-framework/operator-lib v0.6.0/go.mod h1:2Z32GTTJUz2/f+OKcoJXsVnAyRwcXx7mGmQsdhIAIIE=
832833
github.com/operator-framework/operator-registry v1.17.4 h1:bYoWevurGEUshSMu8QNcImhLuPZJ/a4MbsUuvBjFEzA=
833834
github.com/operator-framework/operator-registry v1.17.4/go.mod h1:k0rWVT23QoN1prs9tX8PHjRVXz6FMZfUJ5EIZSrqh9E=
834835
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
@@ -1624,8 +1625,8 @@ sigs.k8s.io/controller-tools v0.6.0 h1:o2Fm1K7CmIp8OVaBtXsWB/ssBAzyoKZPPAGR3Vuxa
16241625
sigs.k8s.io/controller-tools v0.6.0/go.mod h1:baRMVPrctU77F+rfAuH2uPqW93k6yQnZA2dhUOr7ihc=
16251626
sigs.k8s.io/kind v0.10.0/go.mod h1:fb32zUw7ewC47bPwLnwhf47wd/vADtv3c38KP7sjIlo=
16261627
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210702145813-742983631190/go.mod h1:pUhjQx9f/+cn1OtSa5zMohY1lgk9s/9Mbcvwj82lrNk=
1627-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210707171043-359e8aa70c2b h1:fGbw9og/lq/fNi4afnVwSinfaQXkonlbTar9nG95u44=
1628-
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210707171043-359e8aa70c2b/go.mod h1:pUhjQx9f/+cn1OtSa5zMohY1lgk9s/9Mbcvwj82lrNk=
1628+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210803185103-51e4a9aa5055 h1:3f5m0xp0DEsg+Sdrt1Rld8TCEFOH5GKsoYrEpdOzA+s=
1629+
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210803185103-51e4a9aa5055/go.mod h1:pUhjQx9f/+cn1OtSa5zMohY1lgk9s/9Mbcvwj82lrNk=
16291630
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
16301631
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
16311632
sigs.k8s.io/kustomize/api v0.8.5 h1:bfCXGXDAbFbb/Jv5AhMj2BB8a5VAJuuQ5/KU69WtDjQ=

internal/ansible/controller/controller.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package controller
1717
import (
1818
"fmt"
1919
"os"
20+
"reflect"
2021
"strings"
2122
"time"
2223

@@ -33,7 +34,6 @@ import (
3334

3435
"github.com/operator-framework/operator-sdk/internal/ansible/events"
3536
"github.com/operator-framework/operator-sdk/internal/ansible/handler"
36-
"github.com/operator-framework/operator-sdk/internal/ansible/predicate"
3737
"github.com/operator-framework/operator-sdk/internal/ansible/runner"
3838
)
3939

@@ -103,12 +103,17 @@ func Add(mgr manager.Manager, options Options) *controller.Controller {
103103
predicates := []ctrlpredicate.Predicate{
104104
ctrlpredicate.Or(ctrlpredicate.GenerationChangedPredicate{}, libpredicate.NoGenerationPredicate{}),
105105
}
106-
filterPredicate, err := predicate.NewResourceFilterPredicate(options.Selector)
106+
107+
p, err := parsePredicateSelector(options.Selector)
108+
107109
if err != nil {
108-
log.Error(err, "Error creating resource filter predicate")
110+
log.Error(err, "")
109111
os.Exit(1)
110112
}
111-
predicates = append(predicates, filterPredicate)
113+
114+
if p != nil {
115+
predicates = append(predicates, p)
116+
}
112117

113118
u := &unstructured.Unstructured{}
114119
u.SetGroupVersionKind(options.GVK)
@@ -120,3 +125,17 @@ func Add(mgr manager.Manager, options Options) *controller.Controller {
120125

121126
return &c
122127
}
128+
129+
// parsePredicateSelector parses the selector in the WatchOptions and creates a predicate
130+
// that is used to filter resources based on the specified selector
131+
func parsePredicateSelector(selector metav1.LabelSelector) (ctrlpredicate.Predicate, error) {
132+
// If a selector has been specified in watches.yaml, add it to the watch's predicates.
133+
if !reflect.ValueOf(selector).IsZero() {
134+
p, err := ctrlpredicate.LabelSelectorPredicate(selector)
135+
if err != nil {
136+
return nil, fmt.Errorf("error constructing predicate from watches selector: %v", err)
137+
}
138+
return p, nil
139+
}
140+
return nil, nil
141+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 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 controller
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
func TestFilterPredicate(t *testing.T) {
25+
matchLabelPass := make(map[string]string)
26+
matchLabelPass["testKey"] = "testValue"
27+
selectorPass := metav1.LabelSelector{
28+
MatchLabels: matchLabelPass,
29+
}
30+
noSelector := metav1.LabelSelector{}
31+
32+
passPredicate, err := parsePredicateSelector(selectorPass)
33+
assert.Equal(t, nil, err, "Verify that no error is thrown on a valid populated selector")
34+
assert.NotEqual(t, nil, passPredicate, "Verify that a predicate is constructed using a valid selector")
35+
36+
nilPredicate, err := parsePredicateSelector(noSelector)
37+
assert.Equal(t, nil, err, "Verify that no error is thrown on a valid unpopulated selector")
38+
assert.Equal(t, nil, nilPredicate, "Verify correct parsing of an unpopulated selector")
39+
}

internal/ansible/predicate/predicate.go

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

internal/ansible/watches/watches.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,6 @@ var (
8585
ansibleVerbosityDefault = 2
8686
)
8787

88-
// Creates, populates, and returns a LabelSelector object. Used in Unmarshal().
89-
func parseLabelSelector(dls tempLabelSelector) metav1.LabelSelector {
90-
obj := metav1.LabelSelector{}
91-
obj.MatchLabels = dls.MatchLabels
92-
93-
for _, v := range dls.MatchExpressions {
94-
requirement := metav1.LabelSelectorRequirement{
95-
Key: v.Key,
96-
Operator: v.Operator,
97-
Values: v.Values,
98-
}
99-
100-
obj.MatchExpressions = append(obj.MatchExpressions, requirement)
101-
}
102-
103-
return obj
104-
}
105-
106-
// Temporary structs created to store yaml parsing
107-
type tempLabelSelector struct {
108-
MatchLabels map[string]string `yaml:"matchLabels,omitempty"`
109-
MatchExpressions []tempRequirement `json:"matchExpressions,omitempty"`
110-
}
111-
112-
type tempRequirement struct {
113-
Key string `json:"key"`
114-
Operator metav1.LabelSelectorOperator `json:"operator"`
115-
Values []string `json:"values,omitempty"`
116-
}
117-
11888
// Use an alias struct to handle complex types
11989
type alias struct {
12090
Group string `yaml:"group"`
@@ -132,7 +102,7 @@ type alias struct {
132102
MarkUnsafe *bool `yaml:"markUnsafe"`
133103
Blacklist []schema.GroupVersionKind `yaml:"blacklist,omitempty"`
134104
Finalizer *Finalizer `yaml:"finalizer"`
135-
Selector tempLabelSelector `yaml:"selector"`
105+
Selector metav1.LabelSelector `yaml:"selector"`
136106
}
137107

138108
// buildWatch will build Watch based on the values parsed from alias
@@ -201,7 +171,7 @@ func (w *Watch) setValuesFromAlias(tmp alias) error {
201171
return err
202172
}
203173
w.addRolePlaybookPaths(wd)
204-
w.Selector = parseLabelSelector(tmp.Selector)
174+
w.Selector = tmp.Selector
205175

206176
return nil
207177
}

internal/cmd/helm-operator/run/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func run(cmd *cobra.Command, f *flags.Flags) {
202202
WatchDependentResources: *w.WatchDependentResources,
203203
OverrideValues: w.OverrideValues,
204204
MaxConcurrentReconciles: f.MaxConcurrentReconciles,
205+
Selector: w.Selector,
205206
})
206207
if err != nil {
207208
log.Error(err, "Failed to add manager factory to controller.")

0 commit comments

Comments
 (0)