Skip to content

Commit

Permalink
upgrade to latest dependencies (#90)
Browse files Browse the repository at this point in the history
bumping knative.dev/client 95dc71c...0bbb3ec:
  > 0bbb3ec update versions to 0.24 (# 1360)
  > b4af7f2 upgrade to latest dependencies (# 1358)
  > 6491510 Update changelog for 0.24.0 release (# 1356)
  > a086cc9 Add `env-value-from` flag & keep order of env vars in created/updated services (# 1328)
  > ab537bc Improve test coverage of main package (# 1357)
  > 1859299 Update community files (# 1354)
  > 88fd310 Remove force update of go-licenses binary (# 1348)
  > 4da6475 increase code cov for sources (# 1343)
bumping knative.dev/serving 2079293...c75484e:
  > c75484e Update net-istio nightly (# 11610)
  > 4aeada7 Remove unused secret accessor (# 11603)
  > 9bff34a Update net-kourier nightly (# 11602)
  > 074dfcb Update net-certmanager nightly (# 11599)
  > 6894844 Update community files (# 11604)
  > 776c39a Update net-istio nightly (# 11601)
  > dd5ff5f Update net-contour nightly (# 11600)
  > 81e8732 issues/11122 EnableLogStream test flag (# 11598)
  > 20139f4 Update net-istio nightly (# 11595)
  > d4c0f90 Update net-contour nightly (# 11594)
  > 643def2 Update net-certmanager nightly (# 11593)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation authored Jun 30, 2021
1 parent d1be51e commit a73f9df
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 48 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ require (
k8s.io/api v0.20.7
k8s.io/apimachinery v0.20.7
k8s.io/client-go v0.20.7
knative.dev/client v0.23.1-0.20210624140446-95dc71c6313c
knative.dev/client v0.24.0
knative.dev/hack v0.0.0-20210622141627-e28525d8d260
knative.dev/serving v0.23.1-0.20210624133346-20792938f32c
knative.dev/serving v0.24.0
)

replace github.com/go-openapi/spec => github.com/go-openapi/spec v0.19.3
21 changes: 7 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1699,38 +1699,31 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
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/caching v0.0.0-20210618060751-63450f5dc83b/go.mod h1:CeUTkzqGQJInmmOSrfWjWXXG1zJpzFoFyNJ2koktKCg=
knative.dev/caching v0.0.0-20210622183028-95f67e075071/go.mod h1:9gwZcCBtmo9pi1oTgchXcdMNAXAYWklwDmO9uhDsIJE=
knative.dev/client v0.21.0/go.mod h1:1En9uxMhk62EReWR1d66/d3tnpkot/D3vBRfmuidFNc=
knative.dev/client v0.23.1-0.20210624140446-95dc71c6313c h1:QSYjhJqlLAwfS/JE1PGVBZxI+3NtOKR4NAMCX7XoNU8=
knative.dev/client v0.23.1-0.20210624140446-95dc71c6313c/go.mod h1:8GQWMEsT8EzXXnWmD360R95I0GGdns2x/XaN1ENuYd8=
knative.dev/client v0.24.0 h1:p9i3dRGtYm4yB8nAhGUhYCMw5jQmnshxMUKrB2Dt35E=
knative.dev/client v0.24.0/go.mod h1:OLNPIb1QJpW7mji+zsn7k64MqNszfwH3b4LQsKF2304=
knative.dev/eventing v0.21.0/go.mod h1:JjbVEOTJJHqo9CTxbTfrMn018hG8fOr3UfBoCJ7KWaA=
knative.dev/eventing v0.23.1-0.20210623160544-0cb787308255 h1:qD+rUgPdUrQR5ABIGOMXnFtXtM5LwTLu8/445kzS+/U=
knative.dev/eventing v0.23.1-0.20210623160544-0cb787308255/go.mod h1:cHeF82RO/9T0mZvKACrYviARZDiXGLZ2VGPei6AvlGo=
knative.dev/eventing v0.24.0 h1:CoaQwZBizxZyOFJUvFcyb7vYSvpYBmfb4IYRNWUdTPE=
knative.dev/eventing v0.24.0/go.mod h1:9xo0SWkIfpXrx0lvGQO7MUlPF8cu+QCMd2gGxj6wxrU=
knative.dev/hack v0.0.0-20210203173706-8368e1f6eacf/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20210614141220-66ab1a098940/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20210622141627-e28525d8d260 h1:f2eMtOubAOc/Q7JlvFPDKXiPlJVK+VpX2Cot8hRzCgQ=
knative.dev/hack v0.0.0-20210622141627-e28525d8d260/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20210622141627-e28525d8d260/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/networking v0.0.0-20210215030235-088986a1c2a3/go.mod h1:pmAMQjMqQUxpK0UyjE71KljMs6rwDMVIAlvrZsU3I6Y=
knative.dev/networking v0.0.0-20210216014426-94bfc013982b/go.mod h1:Crdn87hxdFd3Jj6PIyrjzGnr8OGHX35k5xo9jlOrjjA=
knative.dev/networking v0.0.0-20210618141751-9b6da1991d38/go.mod h1:A6gUyRVaXmDebDRVsVdcOz65S8JCnEHKprNvAeaj2jE=
knative.dev/networking v0.0.0-20210622182128-53f45d6d2cfa h1:MprAGBX3eRaBZFRXC3ZjsnhnjttfprRVXdxmTeEzC2o=
knative.dev/networking v0.0.0-20210622182128-53f45d6d2cfa/go.mod h1:vwPACNE712tyoEG4fjyUIgfL4xkbXFugx8bxW+QrKn4=
knative.dev/pkg v0.0.0-20210212203835-448ae657fb5f/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/pkg v0.0.0-20210215165523-84c98f3c3e7a/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/pkg v0.0.0-20210216013737-584933f8280b/go.mod h1:TJSdebQOWX5N2bszohOYVi0H1QtXbtlYLuMghAFBMhY=
knative.dev/pkg v0.0.0-20210615092720-192b0c9d6e56/go.mod h1:QVfbwA5ovshGnXDcx54l2QPYhGKppw/JgLYJWe7sA6A=
knative.dev/pkg v0.0.0-20210616195222-841aa7369ca1/go.mod h1:QVfbwA5ovshGnXDcx54l2QPYhGKppw/JgLYJWe7sA6A=
knative.dev/pkg v0.0.0-20210622143227-7521c9239efd/go.mod h1:QVfbwA5ovshGnXDcx54l2QPYhGKppw/JgLYJWe7sA6A=
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80 h1:GHJ3lglE0/YHfBMMJqluqUNLOmsNXh7s7DBnfrkpRMM=
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80/go.mod h1:kGegTnbZ+ljFjAE3E1+8wgaH2LMv8qYi+72o3F3cbdc=
knative.dev/reconciler-test v0.0.0-20210216030508-77f50054d024/go.mod h1:RP/K5xJylB72Go6eAsXYEsQHp4zCCNMNjmsqhvq7wko=
knative.dev/reconciler-test v0.0.0-20210623120544-4d687fd0fec1/go.mod h1:4wqv2WyWUC5yhTesRUVwgjv/fHTHny1RYBfdB6tVDok=
knative.dev/reconciler-test v0.0.0-20210623134345-88c84739abd9/go.mod h1:4wqv2WyWUC5yhTesRUVwgjv/fHTHny1RYBfdB6tVDok=
knative.dev/serving v0.21.0/go.mod h1:PU9k1Y6YMG27XQldEu5agNkcebvSafUXKXPircQYCsE=
knative.dev/serving v0.23.1-0.20210623204144-c54eeabbb984/go.mod h1:U4LEzBJCKzi0lIjTVbWx6vyD3dadIjVk+0pzU0MVo4s=
knative.dev/serving v0.23.1-0.20210624133346-20792938f32c h1:tPD+bfXRcmlzOVenbiZunFPQFmdK8Orl0zfvLtRlaLk=
knative.dev/serving v0.23.1-0.20210624133346-20792938f32c/go.mod h1:l/dhsWs+Y8PAssBxaS/hN4HRQQGy4zxfVHD1xYjl3ns=
knative.dev/serving v0.24.0 h1:MZIXR0r2FCXlTuQQXwLuM9+tV6pl2K6YUtK6tEtDB58=
knative.dev/serving v0.24.0/go.mod h1:l/dhsWs+Y8PAssBxaS/hN4HRQQGy4zxfVHD1xYjl3ns=
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
35 changes: 24 additions & 11 deletions vendor/knative.dev/client/pkg/kn/flags/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import (
// PodSpecFlags to hold the container resource requirements values
type PodSpecFlags struct {
// Direct field manipulation
Image uniqueStringArg
Env []string
EnvFrom []string
Mount []string
Volume []string
Image uniqueStringArg
Env []string
EnvFrom []string
EnvValueFrom []string
Mount []string
Volume []string

Command string
Arg []string
Expand Down Expand Up @@ -82,6 +83,13 @@ func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) []string {
"To unset, specify the environment variable name followed by a \"-\" (e.g., NAME-).")
flagNames = append(flagNames, "env")

flagset.StringArrayVarP(&p.EnvValueFrom, "env-value-from", "", []string{},
"Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). "+
"Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. "+
"You can use this flag multiple times. "+
"To unset a value from a ConfigMap/Secret key reference, append \"-\" to the key, e.g. --env-value-from ENV-.")
flagNames = append(flagNames, "env-value-from")

flagset.StringArrayVarP(&p.EnvFrom, "env-from", "", []string{},
"Add environment variables from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret:). "+
"Example: --env-from cm:myconfigmap or --env-from secret:mysecret. "+
Expand Down Expand Up @@ -150,17 +158,22 @@ func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) []string {
return flagNames
}

// ResolvePodSpec will create corev1.PodSpec based on the flag inputs
func (p *PodSpecFlags) ResolvePodSpec(podSpec *corev1.PodSpec, flags *pflag.FlagSet) error {
// ResolvePodSpec will create corev1.PodSpec based on the flag inputs and all input arguments
func (p *PodSpecFlags) ResolvePodSpec(podSpec *corev1.PodSpec, flags *pflag.FlagSet, allArgs []string) error {
var err error
if flags.Changed("env") {
envMap, err := util.MapFromArrayAllowingSingles(p.Env, "=")

if flags.Changed("env") || flags.Changed("env-value-from") {
envToUpdate, envToRemove, err := util.OrderedMapAndRemovalListFromArray(p.Env, "=")
if err != nil {
return fmt.Errorf("Invalid --env: %w", err)
}

envToRemove := util.ParseMinusSuffix(envMap)
err = UpdateEnvVars(podSpec, envMap, envToRemove)
envValueFromToUpdate, envValueFromToRemove, err := util.OrderedMapAndRemovalListFromArray(p.EnvValueFrom, "=")
if err != nil {
return fmt.Errorf("Invalid --env-value-from: %w", err)
}

err = UpdateEnvVars(podSpec, allArgs, envToUpdate, envToRemove, envValueFromToUpdate, envValueFromToRemove)
if err != nil {
return err
}
Expand Down
121 changes: 103 additions & 18 deletions vendor/knative.dev/client/pkg/kn/flags/podspec_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package flags

import (
"fmt"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -53,20 +52,60 @@ func containerOfPodSpec(spec *corev1.PodSpec) *corev1.Container {

// UpdateEnvVars gives the configuration all the env var values listed in the given map of
// vars. Does not touch any environment variables not mentioned, but it can add
// new env vars and change the values of existing ones, then sort by env key name.
func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove []string) error {
// new env vars and change the values of existing ones.
func UpdateEnvVars(spec *corev1.PodSpec,
allArgs []string, envToUpdate *util.OrderedMap, envToRemove []string, envValueFromToUpdate *util.OrderedMap, envValueFromToRemove []string) error {
container := containerOfPodSpec(spec)
updated := updateEnvVarsFromMap(container.Env, toUpdate)
updated = removeEnvVars(updated, toRemove)
// Sort by env key name
sort.SliceStable(updated, func(i, j int) bool {
return updated[i].Name < updated[j].Name
})

allEnvsToUpdate := util.NewOrderedMap()

envIterator := envToUpdate.Iterator()
envValueFromIterator := envValueFromToUpdate.Iterator()

envKey, envValue, envExists := envIterator.NextString()
envValueFromKey, envValueFromValue, envValueFromExists := envValueFromIterator.NextString()
for _, arg := range allArgs {
// envs are stored as NAME=value
if envExists && isValidEnvArg(arg, envKey, envValue) {
allEnvsToUpdate.Set(envKey, corev1.EnvVar{
Name: envKey,
Value: envValue,
})
envKey, envValue, envExists = envIterator.NextString()
} else if envValueFromExists && isValidEnvValueFromArg(arg, envValueFromKey, envValueFromValue) {
// envs are stored as NAME=secret:sercretName:key or NAME=config-map:cmName:key
envVarSource, err := createEnvVarSource(envValueFromValue)
if err != nil {
return err
}
allEnvsToUpdate.Set(envValueFromKey, corev1.EnvVar{
Name: envValueFromKey,
ValueFrom: envVarSource,
})
envValueFromKey, envValueFromValue, envValueFromExists = envValueFromIterator.NextString()
}
}

updated := updateEnvVarsFromMap(container.Env, allEnvsToUpdate)
updated = removeEnvVars(updated, append(envToRemove, envValueFromToRemove...))

container.Env = updated

return nil
}

// isValidEnvArg checks that the input arg is a valid argument for specifying env value,
// ie. stored as NAME=value
func isValidEnvArg(arg, envKey, envValue string) bool {
return strings.HasPrefix(arg, envKey+"="+envValue) || strings.HasPrefix(arg, "-e="+envKey+"="+envValue) || strings.HasPrefix(arg, "--env="+envKey+"="+envValue)
}

// isValidEnvValueFromArg checks that the input arg is a valid argument for specifying env from value,
// ie. stored as NAME=secret:sercretName:key or NAME=config-map:cmName:key
func isValidEnvValueFromArg(arg, envValueFromKey, envValueFromValue string) bool {
return strings.HasPrefix(arg, envValueFromKey+"="+envValueFromValue) || strings.HasPrefix(arg, "--env-value-from="+envValueFromKey+"="+envValueFromValue)
}

// UpdateEnvFrom updates envFrom
func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) error {
container := containerOfPodSpec(spec)
Expand Down Expand Up @@ -217,18 +256,20 @@ func UpdateImagePullSecrets(spec *corev1.PodSpec, pullsecrets string) {
}

// =======================================================================================
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate map[string]string) []corev1.EnvVar {
set := sets.NewString()
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate *util.OrderedMap) []corev1.EnvVar {
updated := sets.NewString()

for i := range env {
envVar := &env[i]
if val, ok := toUpdate[envVar.Name]; ok {
envVar.Value = val
set.Insert(envVar.Name)
object, present := toUpdate.Get(env[i].Name)
if present {
env[i] = object.(corev1.EnvVar)
updated.Insert(env[i].Name)
}
}
for name, val := range toUpdate {
if !set.Has(name) {
env = append(env, corev1.EnvVar{Name: name, Value: val})
it := toUpdate.Iterator()
for name, envVar, ok := it.Next(); ok; name, envVar, ok = it.Next() {
if !updated.Has(name) {
env = append(env, envVar.(corev1.EnvVar))
}
}
return env
Expand All @@ -246,6 +287,50 @@ func removeEnvVars(env []corev1.EnvVar, toRemove []string) []corev1.EnvVar {
return env
}

func createEnvVarSource(spec string) (*corev1.EnvVarSource, error) {
slices := strings.SplitN(spec, ":", 3)
if len(slices) != 3 {
return nil, fmt.Errorf("argument requires a value in form \"resourceType:name:key\" where \"resourceType\" can be one of \"config-map\" (\"cm\") or \"secret\" (\"sc\"); got %q", spec)
}

typeString := strings.TrimSpace(slices[0])
sourceName := strings.TrimSpace(slices[1])
sourceKey := strings.TrimSpace(slices[2])

var sourceType string
envVarSource := corev1.EnvVarSource{}

switch typeString {
case "config-map", "cm":
sourceType = "ConfigMap"
envVarSource.ConfigMapKeyRef = &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sourceName,
},
Key: sourceKey}
case "secret", "sc":
sourceType = "Secret"
envVarSource.SecretKeyRef = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sourceName,
},
Key: sourceKey}
default:
return nil, fmt.Errorf("unsupported env source type \"%q\"; supported source types are \"config-map\" (\"cm\") and \"secret\" (\"sc\")", slices[0])
}

if len(sourceName) == 0 {
return nil, fmt.Errorf("the name of %s cannot be an empty string", sourceType)
}

if len(sourceKey) == 0 {
return nil, fmt.Errorf("the key referenced by resource %s \"%s\" cannot be an empty string", sourceType, sourceName)
}

return &envVarSource, nil
}

// =======================================================================================
func updateEnvFrom(envFromSources []corev1.EnvFromSource, toUpdate []string) ([]corev1.EnvFromSource, error) {
existingNameSet := make(map[string]bool)

Expand Down
6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ k8s.io/utils/buffer
k8s.io/utils/integer
k8s.io/utils/pointer
k8s.io/utils/trace
# knative.dev/client v0.23.1-0.20210624140446-95dc71c6313c
# knative.dev/client v0.24.0
## explicit
knative.dev/client/lib/test
knative.dev/client/pkg/apis/client
Expand All @@ -778,7 +778,7 @@ knative.dev/client/pkg/sources/v1beta2
knative.dev/client/pkg/util
knative.dev/client/pkg/util/mock
knative.dev/client/pkg/wait
# knative.dev/eventing v0.23.1-0.20210623160544-0cb787308255
# knative.dev/eventing v0.24.0
knative.dev/eventing/pkg/apis/config
knative.dev/eventing/pkg/apis/duck
knative.dev/eventing/pkg/apis/duck/v1
Expand Down Expand Up @@ -849,7 +849,7 @@ knative.dev/pkg/tracing/propagation
knative.dev/pkg/tracing/propagation/tracecontextb3
knative.dev/pkg/tracker
knative.dev/pkg/unstructured
# knative.dev/serving v0.23.1-0.20210624133346-20792938f32c
# knative.dev/serving v0.24.0
## explicit
knative.dev/serving/pkg/apis/autoscaling
knative.dev/serving/pkg/apis/autoscaling/v1alpha1
Expand Down

0 comments on commit a73f9df

Please sign in to comment.