Skip to content

Commit f8a9bbc

Browse files
Updating deps (google#574)
* adding github template for bugs and features * renaming * adding comment * nits * nits * updating to master * missing files * using revision instead of master * dep ensure -update knative.dev/serving knative.dev/pkg knative.dev/eventing hack/update-codegen.sh * fix undefined var and unit test * Updating vendor, moving pkg to 0.13 * adding config leader election * adding config validation to leader election * updating lock * fixing webhook Co-authored-by: Grace Gao <[email protected]>
1 parent aa57d65 commit f8a9bbc

File tree

353 files changed

+7977
-3878
lines changed

Some content is hidden

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

353 files changed

+7977
-3878
lines changed

Gopkg.lock

+24-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ required = [
2828
# Our master branch tracks knative/pkg master or a release.
2929
[[override]]
3030
name = "knative.dev/pkg"
31-
branch = "master"
31+
branch = "release-0.13"
3232

3333
# This is a preemptive override.
3434
[[override]]

cmd/webhook/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"context"
2121

22+
configvalidation "github.com/google/knative-gcp/pkg/apis/configs/validation"
2223
eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1"
2324
messagingv1alpha1 "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1"
2425
pubsubv1alpha1 "github.com/google/knative-gcp/pkg/apis/pubsub/v1alpha1"
@@ -27,6 +28,7 @@ import (
2728
"knative.dev/pkg/configmap"
2829
"knative.dev/pkg/controller"
2930
"knative.dev/pkg/injection/sharedmain"
31+
"knative.dev/pkg/leaderelection"
3032
"knative.dev/pkg/logging"
3133
"knative.dev/pkg/signals"
3234
tracingconfig "knative.dev/pkg/tracing/config"
@@ -114,7 +116,8 @@ func NewConfigValidationController(ctx context.Context, cmw configmap.Watcher) *
114116
configmap.Constructors{
115117
tracingconfig.ConfigName: tracingconfig.NewTracingConfigFromConfigMap,
116118
// metrics.ConfigMapName(): metricsconfig.NewObservabilityConfigFromConfigMap,
117-
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
119+
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
120+
leaderelection.ConfigMapName(): configvalidation.ValidateLeaderElectionConfig,
118121
},
119122
)
120123
}
@@ -128,7 +131,7 @@ func main() {
128131
SecretName: "webhook-certs",
129132
})
130133

131-
sharedmain.MainWithContext(ctx, logconfig.WebhookName(),
134+
sharedmain.WebhookMainWithContext(ctx, logconfig.WebhookName(),
132135
certificates.NewController,
133136
NewConfigValidationController,
134137
NewValidationAdmissionController,

config/201-clusterrole.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ rules:
135135
- scaledobjects
136136
verbs: *everything
137137

138+
- apiGroups:
139+
- coordination.k8s.io
140+
resources:
141+
- leases
142+
verbs: *everything
143+
138144
---
139145
# The role is needed for the aggregated role source-observer in knative-eventing to provide readonly access to "Sources".
140146
# See https://github.com/knative/eventing/blob/master/config/200-source-observer-clusterrole.yaml.

config/500-controller.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ spec:
5151
value: config-logging
5252
- name: CONFIG_OBSERVABILITY_NAME
5353
value: config-observability
54+
- name: CONFIG_LEADERELECTION_NAME
55+
value: config-leader-election
5456
- name: METRICS_DOMAIN
5557
value: cloud.google.com/events
5658
volumeMounts:

config/config-leader-election.yaml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2020 The Knative 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+
# https://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+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: config-leader-election
19+
namespace: cloud-run-events
20+
labels:
21+
events.cloud.google.com/release: devel
22+
data:
23+
# An inactive but valid configuration follows; see example.
24+
resourceLock: "leases"
25+
leaseDuration: "15s"
26+
renewDeadline: "10s"
27+
retryPeriod: "2s"
28+
_example: |
29+
################################
30+
# #
31+
# EXAMPLE CONFIGURATION #
32+
# #
33+
################################
34+
# This block is not actually functional configuration,
35+
# but serves to illustrate the available configuration
36+
# options and document them in a way that is accessible
37+
# to users that `kubectl edit` this config map.
38+
#
39+
# These sample configuration options may be copied out of
40+
# this example block and unindented to be in the data block
41+
# to actually change the configuration.
42+
# resourceLock controls which API resource is used as the basis for the
43+
# leader election lock. Valid values are:
44+
#
45+
# - leases -> use the coordination API
46+
# - configmaps -> use configmaps
47+
# - endpoints -> use endpoints
48+
resourceLock: "leases"
49+
# leaseDuration is how long non-leaders will wait to try to acquire the
50+
# lock; 15 seconds is the value used by core kubernetes controllers.
51+
leaseDuration: "15s"
52+
# renewDeadline is how long a leader will try to renew the lease before
53+
# giving up; 10 seconds is the value used by core kubernetes controllers.
54+
renewDeadline: "10s"
55+
# retryPeriod is how long the leader election client waits between tries of
56+
# actions; 2 seconds is the value used by core kuberntes controllers.
57+
retryPeriod: "2s"
58+
# enabledComponents is a comma-delimited list of component names for which
59+
# leader election is enabled. Valid values are:
60+
#
61+
# - controller
62+
enabledComponents: "controller"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2020 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package validation
18+
19+
import (
20+
"fmt"
21+
22+
corev1 "k8s.io/api/core/v1"
23+
"k8s.io/apimachinery/pkg/util/sets"
24+
kle "knative.dev/pkg/leaderelection"
25+
)
26+
27+
var (
28+
validComponents = sets.NewString(
29+
"controller",
30+
)
31+
)
32+
33+
func ValidateLeaderElectionConfig(configMap *corev1.ConfigMap) (*kle.Config, error) {
34+
config, err := kle.NewConfigFromMap(configMap.Data)
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
for _, component := range config.EnabledComponents.List() {
40+
if !validComponents.Has(component) {
41+
return nil, fmt.Errorf("invalid enabledComponent %q: valid values are %q", component, validComponents.List())
42+
}
43+
}
44+
45+
return config, nil
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2020 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package validation
18+
19+
import (
20+
"errors"
21+
"reflect"
22+
"testing"
23+
"time"
24+
25+
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/util/sets"
27+
kle "knative.dev/pkg/leaderelection"
28+
)
29+
30+
func okConfig() *kle.Config {
31+
return &kle.Config{
32+
ResourceLock: "leases",
33+
LeaseDuration: 15 * time.Second,
34+
RenewDeadline: 10 * time.Second,
35+
RetryPeriod: 2 * time.Second,
36+
EnabledComponents: sets.NewString("controller"),
37+
}
38+
}
39+
40+
func okData() map[string]string {
41+
return map[string]string{
42+
"resourceLock": "leases",
43+
// values in this data come from the defaults suggested in the
44+
// code:
45+
// https://github.com/kubernetes/client-go/blob/kubernetes-1.16.0/tools/leaderelection/leaderelection.go
46+
"leaseDuration": "15s",
47+
"renewDeadline": "10s",
48+
"retryPeriod": "2s",
49+
"enabledComponents": "controller",
50+
}
51+
}
52+
53+
func TestValidateLeaderElectionConfig(t *testing.T) {
54+
cases := []struct {
55+
name string
56+
data map[string]string
57+
expected *kle.Config
58+
err error
59+
}{
60+
{
61+
name: "OK",
62+
data: okData(),
63+
expected: okConfig(),
64+
},
65+
{
66+
name: "invalid component",
67+
data: func() map[string]string {
68+
data := okData()
69+
data["enabledComponents"] = "controller,frobulator"
70+
return data
71+
}(),
72+
err: errors.New(`invalid enabledComponent "frobulator": valid values are ["controller"]`),
73+
},
74+
}
75+
76+
for i := range cases {
77+
tc := cases[i]
78+
actualConfig, actualErr := ValidateLeaderElectionConfig(&corev1.ConfigMap{Data: tc.data})
79+
if !reflect.DeepEqual(tc.err, actualErr) {
80+
t.Errorf("%v: expected error\n%v\ngot:\n%v", tc.name, tc.err, actualErr)
81+
continue
82+
}
83+
84+
if !reflect.DeepEqual(tc.expected, actualConfig) {
85+
t.Errorf("%v: expected config:\n%+v\ngot:\n%+v", tc.name, tc.expected, actualConfig)
86+
continue
87+
}
88+
}
89+
90+
}

0 commit comments

Comments
 (0)