Skip to content

Commit

Permalink
[master] Auto-update dependencies (#3434)
Browse files Browse the repository at this point in the history
Produced via:
  `./hack/update-deps.sh --upgrade && ./hack/update-codegen.sh`
/assign grantr n3wscott
/cc grantr n3wscott
  • Loading branch information
mattmoor authored Jun 29, 2020
1 parent 4ce48fc commit 6c49c66
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 52 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ require (
k8s.io/apiserver v0.17.6
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
k8s.io/utils v0.0.0-20200124190032-861946025e34
knative.dev/pkg v0.0.0-20200626022628-f1ee372577e1
knative.dev/test-infra v0.0.0-20200625195728-62651036b559
knative.dev/pkg v0.0.0-20200627192328-fe0740d31f07
knative.dev/test-infra v0.0.0-20200626234928-7fb82ece3d02
sigs.k8s.io/yaml v1.2.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,8 @@ knative.dev/pkg v0.0.0-20200603222317-b79e4a24ca50/go.mod h1:8IfPj/lpuKHHg82xZCl
knative.dev/pkg v0.0.0-20200611204322-2ddcfef739a2/go.mod h1:rA+FklsrVahwF4a+D63NyHJlzDoAFH81K4J5CYuE3bA=
knative.dev/pkg v0.0.0-20200624210428-eb05e8dd5b5b h1:NFi5BVmuZ81bWigwn3s/NNaf+GeeOGtNlADAbXPYg+E=
knative.dev/pkg v0.0.0-20200624210428-eb05e8dd5b5b/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0=
knative.dev/pkg v0.0.0-20200626022628-f1ee372577e1 h1:4Fi/WnI7uwbop8gjebSfJbPdJd20XWt66ugzEYunlUA=
knative.dev/pkg v0.0.0-20200626022628-f1ee372577e1/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0=
knative.dev/pkg v0.0.0-20200627192328-fe0740d31f07 h1:vV7irILASq3uYOE4R1pUtHYwQBd+A0zLs2E29jgsOnQ=
knative.dev/pkg v0.0.0-20200627192328-fe0740d31f07/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0=
knative.dev/test-infra v0.0.0-20200407185800-1b88cb3b45a5/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ=
knative.dev/test-infra v0.0.0-20200505052144-5ea2f705bb55/go.mod h1:WqF1Azka+FxPZ20keR2zCNtiQA1MP9ZB4BH4HuI+SIU=
knative.dev/test-infra v0.0.0-20200513011557-d03429a76034/go.mod h1:aMif0KXL4g19YCYwsy4Ocjjz5xgPlseYV+B95Oo4JGE=
Expand All @@ -1440,8 +1440,8 @@ knative.dev/test-infra v0.0.0-20200606045118-14ebc4a42974 h1:CrZmlbB+j3ZF/aTrfyy
knative.dev/test-infra v0.0.0-20200606045118-14ebc4a42974/go.mod h1://I6IZIF0QDgs5wotU243ZZ5cTpm6/GthayjUenBBc0=
knative.dev/test-infra v0.0.0-20200617235125-6382dba95484 h1:5D1Fm6aA1T1QQXLb1HkJ5t8gB9pTkhLYak1CCqIP+pE=
knative.dev/test-infra v0.0.0-20200617235125-6382dba95484/go.mod h1:+BfrTJpc++rH30gX/C0QY6NT2eYVzycll52uw6CrQnc=
knative.dev/test-infra v0.0.0-20200625195728-62651036b559 h1:UnUP8ygaXWLi3LWSpoOvhLcHbOE/yf2De57/aBZIzTQ=
knative.dev/test-infra v0.0.0-20200625195728-62651036b559/go.mod h1:HZw00KOJoOIzWOSF6tn+0jfJZHpXRCIZkHooc+hh7yg=
knative.dev/test-infra v0.0.0-20200626234928-7fb82ece3d02 h1:2JWjcOrsB6bddxv9ecMFGkeJBnvZnR65vQIv5UWa8zU=
knative.dev/test-infra v0.0.0-20200626234928-7fb82ece3d02/go.mod h1:HZw00KOJoOIzWOSF6tn+0jfJZHpXRCIZkHooc+hh7yg=
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=
Expand Down
4 changes: 2 additions & 2 deletions vendor/knative.dev/pkg/injection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ for that resource.

#### Annotation based common logic

**krshaped=true may become the default if omitted in the future**
**krshapedlogic=false may be used to omit common reconciler logic**

Reconcilers can handle common logic for resources that conform to the KRShaped
interface. This allows the generated code to automatically increment
ObservedGeneration.

```go
// +genreconciler:krshapedlogic=true
// +genreconciler
```

Setting this annotation will emit the following in the generated reconciler.
Expand Down
2 changes: 1 addition & 1 deletion vendor/knative.dev/pkg/injection/sharedmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func WebhookMainWithConfig(ctx context.Context, component string, cfg *rest.Conf
leConfig := leaderElectionConfig.GetComponentConfig(component)
if leConfig.LeaderElect {
// Signal that we are executing in a context with leader election.
ctx = kle.WithStandardLeaderElectorBuilder(ctx, kubeclient.Get(ctx), leConfig)
ctx = kle.WithDynamicLeaderElectorBuilder(ctx, kubeclient.Get(ctx), leConfig)
}

controllers, webhooks := ControllersAndWebhooksFromCtors(ctx, cmw, ctors...)
Expand Down
42 changes: 36 additions & 6 deletions vendor/knative.dev/pkg/leaderelection/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package leaderelection
import (
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/kelseyhightower/envconfig"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/uuid"
Expand Down Expand Up @@ -126,12 +129,39 @@ type ComponentConfig struct {
RetryPeriod time.Duration
}

// StatefulSetConfig represents the required information for a StatefulSet service.
type StatefulSetConfig struct {
StatefulSetName string
ServiceName string
Port string
Protocol string
// statefulSetID is a envconfig Decodable controller ordinal and name.
type statefulSetID struct {
ssName string
ordinal int
}

func (ssID *statefulSetID) Decode(v string) error {
if i := strings.LastIndex(v, "-"); i != -1 {
ui, err := strconv.ParseUint(v[i+1:], 10, 64)
ssID.ordinal = int(ui)
ssID.ssName = v[:i]
return err
}
return fmt.Errorf("%q is not a valid stateful set controller ordinal", v)
}

var _ envconfig.Decoder = (*statefulSetID)(nil)

// statefulSetConfig represents the required information for a StatefulSet service.
type statefulSetConfig struct {
StatefulSetID statefulSetID `envconfig:"STATEFUL_CONTROLLER_ORDINAL" required:"true"`
ServiceName string `envconfig:"STATEFUL_SERVICE_NAME" required:"true"`
Port string `envconfig:"STATEFUL_SERVICE_PORT" default:"80"`
Protocol string `envconfig:"STATEFUL_SERVICE_PROTOCOL" default:"http"`
}

// newStatefulSetConfig builds a stateful set LE config.
func newStatefulSetConfig() (*statefulSetConfig, error) {
ssc := &statefulSetConfig{}
if err := envconfig.Process("", ssc); err != nil {
return nil, err
}
return ssc, nil
}

func defaultComponentConfig(name string) ComponentConfig {
Expand Down
45 changes: 27 additions & 18 deletions vendor/knative.dev/pkg/leaderelection/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ import (
"knative.dev/pkg/system"
)

// WithDynamicLeaderElectorBuilder sets up the statefulset elector based on environment,
// falling back on the standard elector.
func WithDynamicLeaderElectorBuilder(ctx context.Context, kc kubernetes.Interface, cc ComponentConfig) context.Context {
logger := logging.FromContext(ctx)
ssc, err := newStatefulSetConfig()
if err == nil {
logger.Info("Running with StatefulSet leader election")
return withStatefulSetElectorBuilder(ctx, cc, *ssc)
}
logger.Info("Running with Standard leader election")
return WithStandardLeaderElectorBuilder(ctx, kc, cc)
}

// WithStandardLeaderElectorBuilder infuses a context with the ability to build
// LeaderElectors with the provided component configuration acquiring resource
// locks via the provided kubernetes client.
Expand All @@ -43,10 +56,10 @@ func WithStandardLeaderElectorBuilder(ctx context.Context, kc kubernetes.Interfa
})
}

// WithStatefulSetLeaderElectorBuilder infuses a context with the ability to build
// withStatefulSetElectorBuilder infuses a context with the ability to build
// Electors which are assigned leadership based on the StatefulSet ordinal from
// the provided component configuration.
func WithStatefulSetLeaderElectorBuilder(ctx context.Context, cc ComponentConfig, ssc StatefulSetConfig) context.Context {
func withStatefulSetElectorBuilder(ctx context.Context, cc ComponentConfig, ssc statefulSetConfig) context.Context {
return context.WithValue(ctx, builderKey{}, &statefulSetBuilder{
lec: cc,
ssc: ssc,
Expand All @@ -71,9 +84,9 @@ func BuildElector(ctx context.Context, la reconciler.LeaderAware, name string, e
if val := ctx.Value(builderKey{}); val != nil {
switch builder := val.(type) {
case *standardBuilder:
return builder.BuildElector(ctx, la, name, enq)
return builder.buildElector(ctx, la, name, enq)
case *statefulSetBuilder:
return builder.BuildElector(ctx, la, enq)
return builder.buildElector(ctx, la, enq)
}
}

Expand All @@ -91,7 +104,8 @@ type standardBuilder struct {
lec ComponentConfig
}

func (b *standardBuilder) BuildElector(ctx context.Context, la reconciler.LeaderAware, name string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
func (b *standardBuilder) buildElector(ctx context.Context, la reconciler.LeaderAware,
name string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
logger := logging.FromContext(ctx)

id, err := UniqueID()
Expand Down Expand Up @@ -143,8 +157,7 @@ func (b *standardBuilder) BuildElector(ctx context.Context, la reconciler.Leader
},
},
ReleaseOnCancel: true,

Name: rl.Identity(),
Name: rl.Identity(),
})
if err != nil {
return nil, err
Expand All @@ -160,26 +173,22 @@ func (b *standardBuilder) BuildElector(ctx context.Context, la reconciler.Leader

type statefulSetBuilder struct {
lec ComponentConfig
ssc StatefulSetConfig
ssc statefulSetConfig
}

func (b *statefulSetBuilder) BuildElector(ctx context.Context, la reconciler.LeaderAware, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
func (b *statefulSetBuilder) buildElector(ctx context.Context, la reconciler.LeaderAware, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
logger := logging.FromContext(ctx)

ordinal, err := ControllerOrdinal()
if err != nil {
return nil, err
}

logger.Infof("%s will run in StatefulSet ordinal assignement mode with ordinal %d", b.lec.Component, ordinal)
ordinal := uint32(b.ssc.StatefulSetID.ordinal)
logger.Infof("%s will run in StatefulSet ordinal assignement mode with ordinal %d",
b.lec.Component, ordinal)

return &unopposedElector{
bkt: &bucket{
// The name is the full pod DNS of the owner pod of this bucket.
name: fmt.Sprintf("%s://%s-%d.%s.%s.svc.%s:%s", b.ssc.Protocol,
b.ssc.StatefulSetName, ordinal, b.ssc.ServiceName,
b.ssc.StatefulSetID.ssName, ordinal, b.ssc.ServiceName,
system.Namespace(), network.GetClusterDomainName(), b.ssc.Port),
index: uint32(ordinal),
index: ordinal,
total: b.lec.Buckets,
},
la: la,
Expand Down
22 changes: 5 additions & 17 deletions vendor/knative.dev/pkg/leaderelection/ordinal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,12 @@ limitations under the License.

package leaderelection

import (
"fmt"
"os"
"strconv"
"strings"
)

// If run a process on Kubernetes, the value of this environment variable
// should be set to the pod name via the downward API.
const controllerOrdinalEnv = "CONTROLLER_ORDINAL"

// ControllerOrdinal tries to get ordinal from the pod name of a StatefulSet,
// which is provided from the environment variable CONTROLLER_ORDINAL.
func ControllerOrdinal() (uint64, error) {
v := os.Getenv(controllerOrdinalEnv)
if i := strings.LastIndex(v, "-"); i != -1 {
return strconv.ParseUint(v[i+1:], 10, 64)
func ControllerOrdinal() (int, error) {
ssc, err := newStatefulSetConfig()
if err != nil {
return 0, err
}

return 0, fmt.Errorf("ordinal not found in %s=%s", controllerOrdinalEnv, v)
return ssc.StatefulSetID.ordinal, nil
}
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ k8s.io/utils/buffer
k8s.io/utils/integer
k8s.io/utils/pointer
k8s.io/utils/trace
# knative.dev/pkg v0.0.0-20200626022628-f1ee372577e1
# knative.dev/pkg v0.0.0-20200627192328-fe0740d31f07
## explicit
knative.dev/pkg/apiextensions/storageversion
knative.dev/pkg/apiextensions/storageversion/cmd/migrate
Expand Down Expand Up @@ -1060,7 +1060,7 @@ knative.dev/pkg/webhook/resourcesemantics
knative.dev/pkg/webhook/resourcesemantics/conversion
knative.dev/pkg/webhook/resourcesemantics/defaulting
knative.dev/pkg/webhook/resourcesemantics/validation
# knative.dev/test-infra v0.0.0-20200625195728-62651036b559
# knative.dev/test-infra v0.0.0-20200626234928-7fb82ece3d02
## explicit
knative.dev/test-infra/scripts
# sigs.k8s.io/yaml v1.2.0
Expand Down

0 comments on commit 6c49c66

Please sign in to comment.