upgrade to latest dependencies (#1245)

bumping knative.dev/networking 94bfc01...54c0eb1:
  > 54c0eb1 upgrade to latest dependencies (# 358)
  > d5e05ad Update common github actions (# 357)
bumping knative.dev/serving b9576f5...472f8e2:
  > 472f8e2 drop k8s 1.17 from kind e2e testing (# 10854)
  > c1a0496 Fix race condition with Prober logger in upgrade tests (# 10815)
  > 527416d upgrade to latest dependencies (# 10861)
  > 0282521 Introduces h2c auto-detection support in health prober (# 10628)
  > 4aa9840 Thread the metric aggregation algorithm through collector. (# 10850)
  > 6826a1b Don't validate autoscaling annotations where they're not allowed (# 10847)
  > b039ea5 Update net-contour nightly (# 10853)
  > a8e67e0 Add algorithm possible values and annotation validation. (# 10846)
  > cbc2a29 Update net-istio nightly (# 10849)
  > 56f645c Update net-contour nightly (# 10842)
  > ee588f5 Add the annotation for averaging algorithm selection. (# 10840)
  > 18b149f Update the setup of HTTP01 challenge tests (# 10843)
  > c4193ed relax annotation constraints and some cleanup (# 10837)
  > 6e788d7 Fix KeepAlives for HTTPProbe (# 10820)
  > 86b92e0 bump k8s versions for kind e2e (# 10809)
  > 28b910b More deep cleaning of the Route reconciler it needed for some time. (# 10839)
  > a70d100 Use Revision from context in request log (# 10836)
  > a675c75 Backfill some test coverage for annotation validation (# 10834)
bumping knative.dev/eventing 207aa26...2db6877:
  > 2db6877 Add missing singular resource names to source/sinkbinding crds (# 4992)
  > 184fa2f mtping adapter now cleans up internal cache when it stops leading (# 4908)
  > 6fb67cd update deps + codegen (# 4990)
  > 00b44e9 Format markdown (# 4980)
  > 235dba5 refactor for better testability, add ut (# 4979)
  > 44b0a0e Add roadmap for 2021 for Eventing, Eventing Sources and Event Delivery WGs (# 4863)
  > 5451f19 add more ut coverage (# 4978)
bumping knative.dev/pkg 584933f...9039dc1:
  > 9039dc1 moved release docs to github.com/knative/release (# 2040)
  > 07b5ddf add demoteFunc controller option (# 2033)
  > 8a8de5f Move IsKProbe to drainer, since it's the only place it's used (# 2038)
  > 5367a43 Fix potential deadlock when k8s client is used (# 2031)
  > b5bf07b adding retry event count metric for source (# 2016)
  > 17a36e7 Format markdown (# 2037)
  > 29be1c1 Add the release badge for all of the repos (# 2035)
  > e90ac15 Remove the system.Clock and it's mock in a different location (# 2034)
  > 8a9bf76 Add symmetric filter helped based on OwnerRefable. (# 2032)
  > 29092fe Format markdown (# 2030)
  > d733bb4 Add nightly badged to release tables (# 2029)
  > 7b5bcc3 Use the constant for UserAgent (# 2028)
  > 86a8236 Format markdown (# 2025)
  > 6c2f94a Unregister views to avoid slow oom issue during meter cleanup (# 2005)
  > 7689cce Update common github actions (# 2024)
  > f4650d8 Add releasability badges for each repo (# 2023)

Signed-off-by: Knative Automation <automation@knative.team>
This commit is contained in:
knative-automation 2021-03-01 15:06:49 -08:00 committed by GitHub
parent 30be4b6efc
commit 270e322401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 255 additions and 153 deletions

8
go.mod
View File

@ -21,11 +21,11 @@ require (
k8s.io/cli-runtime v0.19.7
k8s.io/client-go v0.19.7
k8s.io/code-generator v0.19.7
knative.dev/eventing v0.21.0
knative.dev/eventing v0.21.1-0.20210228124848-2db68776f120
knative.dev/hack v0.0.0-20210203173706-8368e1f6eacf
knative.dev/networking v0.0.0-20210216014426-94bfc013982b
knative.dev/pkg v0.0.0-20210216013737-584933f8280b
knative.dev/serving v0.21.0
knative.dev/networking v0.0.0-20210301023148-54c0eb153147
knative.dev/pkg v0.0.0-20210226182947-9039dc189ced
knative.dev/serving v0.21.1-0.20210301115148-472f8e2bacf2
sigs.k8s.io/yaml v1.2.0
)

24
go.sum
View File

@ -1305,21 +1305,21 @@ k8s.io/utils v0.0.0-20200729134348-d5654de09c73 h1:uJmqzgNWG7XyClnU/mLPBWwfKKF1K
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 h1:0T5IaWHO3sJTEmCP6mUlBvMukxPKUQWqiI/YuiBNMiQ=
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
knative.dev/caching v0.0.0-20210215030244-1212288570f0/go.mod h1:rAPalJe9Lx3jHffJpackk5WjZYl3j2QvXUgw0GPllxQ=
knative.dev/eventing v0.21.0 h1:oZoL0lXXslUClNvoi5mLO2YI6zn2C8qg80mz8Y6Vmkg=
knative.dev/eventing v0.21.0/go.mod h1:JjbVEOTJJHqo9CTxbTfrMn018hG8fOr3UfBoCJ7KWaA=
knative.dev/caching v0.0.0-20210216192653-d1dfa6451cd1/go.mod h1:1UeUQ6zQ3vHtZRpfuAW/f5oXb11EBqICfJqIzOeOrqU=
knative.dev/eventing v0.21.1-0.20210228124848-2db68776f120 h1:FMOaAAdp0EQEQRPckjGgVtOZIuT3XxcSUcfF1bloOzQ=
knative.dev/eventing v0.21.1-0.20210228124848-2db68776f120/go.mod h1:KtN2FEhPzxyqXKxpJufdq0lzL3Iu+5qjFqBal8Lg2tQ=
knative.dev/hack v0.0.0-20210203173706-8368e1f6eacf h1:u4cY4jr2LYvhoz/1HBWEPsMiLkm0HMdDTfmmw1RE8zE=
knative.dev/hack v0.0.0-20210203173706-8368e1f6eacf/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/networking v0.0.0-20210215030235-088986a1c2a3/go.mod h1:pmAMQjMqQUxpK0UyjE71KljMs6rwDMVIAlvrZsU3I6Y=
knative.dev/networking v0.0.0-20210216014426-94bfc013982b h1:708bHZC2RPjdx8MLH7OASqGP+fhmarJJxVIZoIy+msY=
knative.dev/networking v0.0.0-20210216014426-94bfc013982b/go.mod h1:Crdn87hxdFd3Jj6PIyrjzGnr8OGHX35k5xo9jlOrjjA=
knative.dev/pkg v0.0.0-20210212203835-448ae657fb5f/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/networking v0.0.0-20210216193011-d5e05ad323f0/go.mod h1:Crdn87hxdFd3Jj6PIyrjzGnr8OGHX35k5xo9jlOrjjA=
knative.dev/networking v0.0.0-20210301023148-54c0eb153147 h1:dX51VdzJFfOcpbz3qvD3ohmg0A+oX/qil3r+dHbFtS8=
knative.dev/networking v0.0.0-20210301023148-54c0eb153147/go.mod h1:AZjAFUWHJp9+HCc3Zg6766X9FSptM10HaWP7Ff1U63I=
knative.dev/pkg v0.0.0-20210215165523-84c98f3c3e7a/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/pkg v0.0.0-20210216013737-584933f8280b h1:2v+GBBenjPXhtk3KX/YqxCQVBU6o/AaRkkqE58lgFRQ=
knative.dev/pkg v0.0.0-20210216013737-584933f8280b/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/reconciler-test v0.0.0-20210216030508-77f50054d024/go.mod h1:RP/K5xJylB72Go6eAsXYEsQHp4zCCNMNjmsqhvq7wko=
knative.dev/serving v0.21.0 h1:bdg0JqNovzlMQB2IxXU/iJKF2zPZH6/yXiwiUtr7vtY=
knative.dev/serving v0.21.0/go.mod h1:PU9k1Y6YMG27XQldEu5agNkcebvSafUXKXPircQYCsE=
knative.dev/pkg v0.0.0-20210225221047-07b5ddfaea60/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/pkg v0.0.0-20210226182947-9039dc189ced h1:OCtTbXsJhiR35qCDxFj9Xc8sU3i87ePbc7YlHCt0al4=
knative.dev/pkg v0.0.0-20210226182947-9039dc189ced/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/reconciler-test v0.0.0-20210223181346-209f32c8cdc4/go.mod h1:RP/K5xJylB72Go6eAsXYEsQHp4zCCNMNjmsqhvq7wko=
knative.dev/serving v0.21.1-0.20210301115148-472f8e2bacf2 h1:XC/vJOFmwOAzOQXs1vCEOfk/3ya79SFhpVHGqDQToSk=
knative.dev/serving v0.21.1-0.20210301115148-472f8e2bacf2/go.mod h1:a4eAD31lUwrx8M7xu1EX7Q5tPEIcGdT/XmA3RRezV70=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=

View File

@ -271,6 +271,9 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu
rec.skipStatusUpdates = true
}
{{- end}}
if opts.DemoteFunc != nil {
rec.DemoteFunc = opts.DemoteFunc
}
}
rec.Recorder = createRecorder(ctx, agentName)

View File

@ -363,6 +363,9 @@ func NewReconciler(ctx {{.contextContext|raw}}, logger *{{.zapSugaredLogger|raw}
rec.skipStatusUpdates = true
}
{{- end}}
if opts.DemoteFunc != nil {
rec.DemoteFunc = opts.DemoteFunc
}
}
return rec

View File

@ -152,6 +152,13 @@ func FilterControllerGK(gk schema.GroupKind) func(obj interface{}) bool {
}
}
// FilterController makes it simple to create FilterFunc's for use with
// cache.FilteringResourceEventHandler that filter based on the
// controlling resource.
func FilterController(r kmeta.OwnerRefable) func(obj interface{}) bool {
return FilterControllerGK(r.GetGroupVersionKind().GroupKind())
}
// FilterWithName makes it simple to create FilterFunc's for use with
// cache.FilteringResourceEventHandler that filter based on a name.
func FilterWithName(name string) func(obj interface{}) bool {

View File

@ -35,6 +35,9 @@ type Options struct {
// SkipStatusUpdates configures this reconciler to either do automated status
// updates (default) or skip them if this is set to true.
SkipStatusUpdates bool
// DemoteFunc configures the demote function this reconciler uses
DemoteFunc func(b reconciler.Bucket)
}
// OptionsFn is a callback method signature that accepts an Impl and returns

View File

@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"strings"
"sync"
"go.opencensus.io/resource"
"go.opencensus.io/stats/view"
@ -32,9 +31,14 @@ import (
var (
curMetricsExporter view.Exporter
curMetricsConfig *metricsConfig
metricsMux sync.RWMutex
mWorker *metricsWorker
)
func init() {
mWorker = newMetricsWorker()
go mWorker.start()
}
// SecretFetcher is a function (extracted from SecretNamespaceLister) for fetching
// a specific Secret. This avoids requiring global or namespace list in controllers.
type SecretFetcher func(string) (*corev1.Secret, error)
@ -154,29 +158,15 @@ func UpdateExporter(ctx context.Context, ops ExporterOptions, logger *zap.Sugare
// Updating the metrics config and the metrics exporters needs to be atomic to
// avoid using an outdated metrics config with new exporters.
metricsMux.Lock()
defer metricsMux.Unlock()
if isNewExporterRequired(newConfig) {
logger.Info("Flushing the existing exporter before setting up the new exporter.")
flushGivenExporter(curMetricsExporter)
e, f, err := newMetricsExporter(newConfig, logger)
if err != nil {
logger.Errorw("Failed to update a new metrics exporter based on metric config", zap.Error(err), "config", newConfig)
updateCmd := &updateMetricsConfigWithExporter{
ctx: ctx,
newConfig: newConfig,
done: make(chan error),
}
mWorker.c <- updateCmd
err = <-updateCmd.done
return err
}
existingConfig := curMetricsConfig
curMetricsExporter = e
if err := setFactory(f); err != nil {
logger.Errorw("Failed to update metrics factory when loading metric config", zap.Error(err), "config", newConfig)
return err
}
logger.Infof("Successfully updated the metrics exporter; old config: %v; new config %v", existingConfig, newConfig)
}
setCurMetricsConfigUnlocked(newConfig)
return nil
}
// isNewExporterRequired compares the non-nil newConfig against curMetricsConfig. When backend changes,
// or stackdriver project ID changes for stackdriver backend, we need to update the metrics exporter.
@ -228,27 +218,35 @@ func newMetricsExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.
}
func getCurMetricsExporter() view.Exporter {
metricsMux.RLock()
defer metricsMux.RUnlock()
return curMetricsExporter
readCmd := &readExporter{done: make(chan *view.Exporter)}
mWorker.c <- readCmd
e := <-readCmd.done
return *e
}
func setCurMetricsExporter(e view.Exporter) {
metricsMux.Lock()
defer metricsMux.Unlock()
curMetricsExporter = e
setCmd := &setExporter{
newExporter: &e,
done: make(chan struct{}),
}
mWorker.c <- setCmd
<-setCmd.done
}
func getCurMetricsConfig() *metricsConfig {
metricsMux.RLock()
defer metricsMux.RUnlock()
return curMetricsConfig
readCmd := &readMetricsConfig{done: make(chan *metricsConfig)}
mWorker.c <- readCmd
cfg := <-readCmd.done
return cfg
}
func setCurMetricsConfig(c *metricsConfig) {
metricsMux.Lock()
defer metricsMux.Unlock()
setCurMetricsConfigUnlocked(c)
setCmd := &setMetricsConfig{
newConfig: c,
done: make(chan struct{}),
}
mWorker.c <- setCmd
<-setCmd.done
}
func setCurMetricsConfigUnlocked(c *metricsConfig) {

View File

@ -0,0 +1,111 @@
/*
Copyright 2021 The Knative 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 metrics
import (
"context"
"go.opencensus.io/stats/view"
"go.uber.org/zap"
"knative.dev/pkg/logging"
)
type metricsWorker struct {
c chan command
}
func newMetricsWorker() *metricsWorker {
return &metricsWorker{c: make(chan command)}
}
type command interface {
handleCommand(w *metricsWorker)
}
type readExporter struct {
done chan *view.Exporter
}
type setExporter struct {
newExporter *view.Exporter
done chan struct{}
}
type readMetricsConfig struct {
done chan *metricsConfig
}
type updateMetricsConfigWithExporter struct {
ctx context.Context
newConfig *metricsConfig
done chan error
}
type setMetricsConfig struct {
newConfig *metricsConfig
done chan struct{}
}
func (cmd *readMetricsConfig) handleCommand(w *metricsWorker) {
cmd.done <- curMetricsConfig
}
func (cmd *setMetricsConfig) handleCommand(w *metricsWorker) {
setCurMetricsConfigUnlocked(cmd.newConfig)
cmd.done <- struct{}{}
}
func (cmd *updateMetricsConfigWithExporter) handleCommand(w *metricsWorker) {
ctx := cmd.ctx
logger := logging.FromContext(ctx)
if isNewExporterRequired(cmd.newConfig) {
logger.Info("Flushing the existing exporter before setting up the new exporter.")
flushGivenExporter(curMetricsExporter)
e, f, err := newMetricsExporter(cmd.newConfig, logger)
if err != nil {
logger.Errorw("Failed to update a new metrics exporter based on metric config", zap.Error(err), "config", cmd.newConfig)
cmd.done <- err
return
}
existingConfig := curMetricsConfig
curMetricsExporter = e
if err := setFactory(f); err != nil {
logger.Errorw("Failed to update metrics factory when loading metric config", zap.Error(err), "config", cmd.newConfig)
cmd.done <- err
return
}
logger.Infof("Successfully updated the metrics exporter; old config: %v; new config %v", existingConfig, cmd.newConfig)
}
setCurMetricsConfigUnlocked(cmd.newConfig)
cmd.done <- nil
}
func (w *metricsWorker) start() {
for {
cmd := <-w.c
cmd.handleCommand(w)
}
}
func (cmd *setExporter) handleCommand(w *metricsWorker) {
curMetricsExporter = *cmd.newExporter
cmd.done <- struct{}{}
}
func (cmd *readExporter) handleCommand(w *metricsWorker) {
cmd.done <- &curMetricsExporter
}

View File

@ -82,10 +82,16 @@ func cleanup() {
expiryCutoff := allMeters.clock.Now().Add(-1 * maxMeterExporterAge)
allMeters.lock.Lock()
defer allMeters.lock.Unlock()
resourceViews.lock.Lock()
defer resourceViews.lock.Unlock()
for key, meter := range allMeters.meters {
if key != "" && meter.t.Before(expiryCutoff) {
flushGivenExporter(meter.e)
// Make a copy of views to avoid data races
viewsCopy := copyViews(resourceViews.views)
meter.m.Unregister(viewsCopy...)
delete(allMeters.meters, key)
meter.m.Stop()
}
}
}
@ -139,7 +145,7 @@ func RegisterResourceView(views ...*view.View) error {
return nil
}
// UnregisterResourceView is similar to view.Unregiste(), except that it will
// UnregisterResourceView is similar to view.Unregister(), except that it will
// unregister the view across all Resources tracked byt he system, rather than
// simply the default view.
func UnregisterResourceView(views ...*view.View) {

View File

@ -17,7 +17,6 @@ limitations under the License.
package network
import (
"fmt"
"net/http"
"strings"
"time"
@ -52,33 +51,19 @@ const (
// uses to find out which version of the networking config is deployed.
HashHeaderName = "K-Network-Hash"
// KubeProbeUAPrefix is the prefix for the User-Agent header.
// Since K8s 1.8, prober requests have
// User-Agent = "kube-probe/{major-version}.{minor-version}".
KubeProbeUAPrefix = "kube-probe/"
// KubeletProbeHeaderName is the header name to augment the probes, because
// Istio with mTLS rewrites probes, but their probes pass a different
// user-agent. So we augment the probes with this header.
// user-agent.
KubeletProbeHeaderName = "K-Kubelet-Probe"
)
// IsKubeletProbe returns true if the request is a Kubernetes probe.
func IsKubeletProbe(r *http.Request) bool {
return strings.HasPrefix(r.Header.Get("User-Agent"), KubeProbeUAPrefix) ||
return strings.HasPrefix(r.Header.Get(UserAgentKey), KubeProbeUAPrefix) ||
r.Header.Get(KubeletProbeHeaderName) != ""
}
// IsKProbe returns true if the request is a knatvie probe.
func IsKProbe(r *http.Request) bool {
return r.Header.Get(ProbeHeaderName) == ProbeHeaderValue
}
// ServeKProbe serve KProbe requests.
func ServeKProbe(w http.ResponseWriter, r *http.Request) {
hh := r.Header.Get(HashHeaderName)
if hh == "" {
http.Error(w, fmt.Sprintf("a probe request must contain a non-empty %q header", HashHeaderName), http.StatusBadRequest)
return
}
w.Header().Set(HashHeaderName, hh)
w.WriteHeader(http.StatusOK)
}

View File

@ -1,32 +0,0 @@
/*
Copyright 2019 The Knative 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 system
import (
"time"
)
// Mockable interface for time based testing
type Clock interface {
Now() time.Time
}
type RealClock struct{}
func (RealClock) Now() time.Time {
return time.Now()
}

View File

@ -58,6 +58,7 @@ func ValidateAnnotations(ctx context.Context, config *autoscalerconfig.Config, a
Also(validateLastPodRetention(anns)).
Also(validateScaleDownDelay(anns)).
Also(validateMetric(anns)).
Also(validateAlgorithm(anns)).
Also(validateInitialScale(config, anns))
}
@ -70,6 +71,22 @@ func validateClass(annotations map[string]string) *apis.FieldError {
return nil
}
func validateAlgorithm(annotations map[string]string) *apis.FieldError {
// Not a KPA? Don't validate, custom autoscalers might have custom values.
if c := annotations[ClassAnnotationKey]; c != KPA {
return nil
}
if a := annotations[MetricAggregationAlgorithmKey]; a != "" {
switch a {
case MetricAggregationAlgorithmLinear, MetricAggregationAlgorithmWeightedExponential:
return nil
default:
return apis.ErrInvalidValue(a, MetricAggregationAlgorithmKey)
}
}
return nil
}
func validateFloats(annotations map[string]string) (errs *apis.FieldError) {
if v, ok := annotations[PanicWindowPercentageAnnotationKey]; ok {
if fv, err := strconv.ParseFloat(v, 64); err != nil {

View File

@ -83,6 +83,28 @@ const (
// scale-to-zero-pod-retention-period global setting.
ScaleToZeroPodRetentionPeriodKey = GroupName + "/scaleToZeroPodRetentionPeriod"
// MetricAggregationAlgorithmKey is the annotation that can be used for selection
// of the algorithm to use for averaging metric data in the Autoscaler.
// Since autoscalers are a pluggable concept, this field is only validated
// for Revisions that are owned by Knative Pod Autoscaler.
// The algorithm will apply to both panic and stagble windows.
// NB: this is an Alpha feature and can be removed or modified
// at any point.
// Possible values for KPA are:
// - empty/missing or "linear" — linear average over the whole
// metric window (default);
// - weightedExponential — weighted average with exponential decay.
// KPA will compute the decay multiplier automatically based on the window size
// and it is at least 0.2. This algorithm might not utilize all the values
// in the window, due to their coefficients being infinitesimal.
MetricAggregationAlgorithmKey = GroupName + "/metricAggregationAlgorithm"
// MetricAggregationAlgorithmLinear is the linear aggregation algorithm with all weights
// equal to 1.
MetricAggregationAlgorithmLinear = "linear"
// MetricAggregationAlgorithmWeightedExponential is the weighted aggregation algorithm
// with exponentially decaying weights.
MetricAggregationAlgorithmWeightedExponential = "weightedExponential"
// WindowAnnotationKey is the annotation to specify the time
// interval over which to calculate the average metric. Larger
// values result in more smoothing. For example,

View File

@ -26,7 +26,7 @@ import (
// Validate validates the entire Metric.
func (m *Metric) Validate(ctx context.Context) *apis.FieldError {
return serving.ValidateObjectMetadata(ctx, m.GetObjectMeta()).ViaField("metadata").
return serving.ValidateObjectMetadata(ctx, m.GetObjectMeta(), true).ViaField("metadata").
Also(m.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec"))
}

View File

@ -26,7 +26,7 @@ import (
// Validate implements apis.Validatable interface.
func (pa *PodAutoscaler) Validate(ctx context.Context) *apis.FieldError {
return serving.ValidateObjectMetadata(ctx, pa.GetObjectMeta()).ViaField("metadata").
return serving.ValidateObjectMetadata(ctx, pa.GetObjectMeta(), true).ViaField("metadata").
Also(pa.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec"))
}

View File

@ -51,6 +51,7 @@ func defaultFeaturesConfig() *Features {
PodSpecSecurityContext: Disabled,
PodSpecTolerations: Disabled,
TagHeaderBasedRouting: Disabled,
AutoDetectHTTP2: Disabled,
}
}
@ -68,7 +69,8 @@ func NewFeaturesConfigFromMap(data map[string]string) (*Features, error) {
asFlag("kubernetes.podspec-runtimeclassname", &nc.PodSpecRuntimeClassName),
asFlag("kubernetes.podspec-securitycontext", &nc.PodSpecSecurityContext),
asFlag("kubernetes.podspec-tolerations", &nc.PodSpecTolerations),
asFlag("tag-header-based-routing", &nc.TagHeaderBasedRouting)); err != nil {
asFlag("tag-header-based-routing", &nc.TagHeaderBasedRouting),
asFlag("autodetect-http2", &nc.AutoDetectHTTP2)); err != nil {
return nil, err
}
return nc, nil
@ -91,6 +93,7 @@ type Features struct {
PodSpecSecurityContext Flag
PodSpecTolerations Flag
TagHeaderBasedRouting Flag
AutoDetectHTTP2 Flag
}
// asFlag parses the value at key as a Flag into the target, if it exists.

View File

@ -24,33 +24,27 @@ import (
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"knative.dev/pkg/apis"
"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/config"
)
var (
allowedAnnotations = sets.NewString(
CreatorAnnotation,
ForceUpgradeAnnotationKey,
RevisionLastPinnedAnnotationKey,
RevisionPreservedAnnotationKey,
RolloutDurationKey,
RoutesAnnotationKey,
RoutingStateModifiedAnnotationKey,
UpdaterAnnotation,
)
)
// ValidateObjectMetadata validates that `metadata` stanza of the
// ValidateObjectMetadata validates that the `metadata` stanza of the
// resources is correct.
func ValidateObjectMetadata(ctx context.Context, meta metav1.Object) *apis.FieldError {
return apis.ValidateObjectMetadata(meta).
Also(autoscaling.ValidateAnnotations(ctx, config.FromContextOrDefaults(ctx).Autoscaler, meta.GetAnnotations()).
Also(validateKnativeAnnotations(meta.GetAnnotations())).
ViaField("annotations"))
// If `allowAutoscalingAnnotations` is true autoscaling annotations, if
// present, are validated. If `allowAutoscalingAnnotations` is false
// autoscaling annotations are validated not to be present.
func ValidateObjectMetadata(ctx context.Context, meta metav1.Object, allowAutoscalingAnnotations bool) *apis.FieldError {
errs := apis.ValidateObjectMetadata(meta)
if allowAutoscalingAnnotations {
errs = errs.Also(autoscaling.ValidateAnnotations(ctx, config.FromContextOrDefaults(ctx).Autoscaler, meta.GetAnnotations()).ViaField("annotations"))
} else {
errs = errs.Also(ValidateHasNoAutoscalingAnnotation(meta.GetAnnotations()).ViaField("annotations"))
}
return errs
}
// ValidateRolloutDurationAnnotation validates the rollout duration annotation.
@ -81,15 +75,6 @@ func ValidateRolloutDurationAnnotation(annos map[string]string) (errs *apis.Fiel
return errs
}
func validateKnativeAnnotations(annotations map[string]string) (errs *apis.FieldError) {
for key := range annotations {
if !allowedAnnotations.Has(key) && strings.HasPrefix(key, GroupNamePrefix) {
errs = errs.Also(apis.ErrInvalidKeyName(key, apis.CurrentField))
}
}
return errs
}
// ValidateHasNoAutoscalingAnnotation validates that the respective entity does not have
// annotations from the autoscaling group. It's to be used to validate Service and
// Configuration.

View File

@ -91,18 +91,12 @@ const (
// DomainMappingLabelKey is the label key attached to Ingress resources to indicate
// which DomainMapping triggered their creation.
DomainMappingLabelKey = GroupName + "/domainmapping"
DomainMappingLabelKey = GroupName + "/domainMapping"
// ConfigurationGenerationLabelKey is the label key attached to a Revision indicating the
// metadata generation of the Configuration that created this revision
ConfigurationGenerationLabelKey = GroupName + "/configurationGeneration"
// ForceUpgradeAnnotationKey is the annotation which was added to resources
// upgraded from v1alpha1.
// This annotation is no longer used since v1alpha1 was removed, but
// must continue to be allowed since it may be present on existing resources.
ForceUpgradeAnnotationKey = GroupName + "/forceUpgrade"
// CreatorAnnotation is the annotation key to describe the user that
// created the resource.
CreatorAnnotation = GroupName + "/creator"

View File

@ -31,9 +31,8 @@ func (c *Configuration) Validate(ctx context.Context) (errs *apis.FieldError) {
// have changed (i.e. due to config-defaults changes), we elide the metadata and
// spec validation.
if !apis.IsInStatusUpdate(ctx) {
errs = errs.Also(serving.ValidateObjectMetadata(ctx, c.GetObjectMeta()))
errs = errs.Also(serving.ValidateObjectMetadata(ctx, c.GetObjectMeta(), false))
errs = errs.Also(c.validateLabels().ViaField("labels"))
errs = errs.Also(serving.ValidateHasNoAutoscalingAnnotation(c.GetAnnotations()).ViaField("annotations"))
errs = errs.ViaField("metadata")
ctx = apis.WithinParent(ctx, c.ObjectMeta)

View File

@ -32,7 +32,7 @@ import (
// Validate ensures Revision is properly configured.
func (r *Revision) Validate(ctx context.Context) *apis.FieldError {
errs := serving.ValidateObjectMetadata(ctx, r.GetObjectMeta()).Also(
errs := serving.ValidateObjectMetadata(ctx, r.GetObjectMeta(), true).Also(
r.ValidateLabels().ViaField("labels")).ViaField("metadata")
errs = errs.Also(r.Status.Validate(apis.WithinStatus(ctx)).ViaField("status"))

View File

@ -28,7 +28,7 @@ import (
// Validate makes sure that Route is properly configured.
func (r *Route) Validate(ctx context.Context) *apis.FieldError {
errs := serving.ValidateObjectMetadata(ctx, r.GetObjectMeta()).Also(
errs := serving.ValidateObjectMetadata(ctx, r.GetObjectMeta(), false).Also(
r.validateLabels().ViaField("labels"))
errs = errs.Also(serving.ValidateRolloutDurationAnnotation(
r.GetAnnotations()).ViaField("annotations"))

View File

@ -31,12 +31,10 @@ func (s *Service) Validate(ctx context.Context) (errs *apis.FieldError) {
// have changed (i.e. due to config-defaults changes), we elide the metadata and
// spec validation.
if !apis.IsInStatusUpdate(ctx) {
errs = errs.Also(serving.ValidateObjectMetadata(ctx, s.GetObjectMeta()))
errs = errs.Also(serving.ValidateObjectMetadata(ctx, s.GetObjectMeta(), false))
errs = errs.Also(s.validateLabels().ViaField("labels"))
errs = errs.Also(serving.ValidateRolloutDurationAnnotation(
s.GetAnnotations()).ViaField("annotations"))
errs = errs.Also(serving.ValidateHasNoAutoscalingAnnotation(
s.GetAnnotations()).ViaField("annotations"))
errs = errs.ViaField("metadata")
ctx = apis.WithinParent(ctx, s.ObjectMeta)

8
vendor/modules.txt vendored
View File

@ -771,7 +771,7 @@ k8s.io/kube-openapi/pkg/util/sets
k8s.io/utils/buffer
k8s.io/utils/integer
k8s.io/utils/trace
# knative.dev/eventing v0.21.0
# knative.dev/eventing v0.21.1-0.20210228124848-2db68776f120
## explicit
knative.dev/eventing/pkg/apis/config
knative.dev/eventing/pkg/apis/configs
@ -805,12 +805,12 @@ knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2/fake
# knative.dev/hack v0.0.0-20210203173706-8368e1f6eacf
## explicit
knative.dev/hack
# knative.dev/networking v0.0.0-20210216014426-94bfc013982b
# knative.dev/networking v0.0.0-20210301023148-54c0eb153147
## explicit
knative.dev/networking/pkg
knative.dev/networking/pkg/apis/networking
knative.dev/networking/pkg/apis/networking/v1alpha1
# knative.dev/pkg v0.0.0-20210216013737-584933f8280b
# knative.dev/pkg v0.0.0-20210226182947-9039dc189ced
## explicit
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
@ -854,7 +854,7 @@ knative.dev/pkg/tracing/config
knative.dev/pkg/tracing/propagation
knative.dev/pkg/tracing/propagation/tracecontextb3
knative.dev/pkg/tracker
# knative.dev/serving v0.21.0
# knative.dev/serving v0.21.1-0.20210301115148-472f8e2bacf2
## explicit
knative.dev/serving/pkg/apis/autoscaling
knative.dev/serving/pkg/apis/autoscaling/v1alpha1