diff --git a/Gopkg.lock b/Gopkg.lock index a7bab94b..4167c102 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -966,7 +966,7 @@ [[projects]] branch = "master" - digest = "1:7912249df5f43ca10fa1c3f8a3febdc3c0f7b320698787fa73c9fb1920a832d6" + digest = "1:9a3d6a5933182bb0ac923b36a7e581b19ea23edeb6684eabe14002758cd7b067" name = "knative.dev/pkg" packages = [ "apis", @@ -986,18 +986,18 @@ "reconciler", ] pruneopts = "T" - revision = "0840da9555a3a75f801abc1d654fb00dfe9a687a" + revision = "9f9f7bea94e15840f36f08b90a2c03203e886f91" [[projects]] branch = "master" - digest = "1:3f2366ce9a05503ac8da902b58e898c285cc9a972e0e89fda0b2a2fedcd4fb46" + digest = "1:2987a1db00b983af9e5d5281639a754fb6449eef01e6a375894829eaec17cb2a" name = "knative.dev/test-infra" packages = [ "scripts", "tools/dep-collector", ] pruneopts = "UT" - revision = "0042e9ca752c8339c3c245e1d2c76b891a144b7e" + revision = "9a501343b4dafbac1a1a5dcfe2cb46975a78abb5" [[projects]] digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c" diff --git a/vendor/knative.dev/pkg/kvstore/kvstore.go b/vendor/knative.dev/pkg/kvstore/kvstore.go new file mode 100644 index 00000000..be8ed2b6 --- /dev/null +++ b/vendor/knative.dev/pkg/kvstore/kvstore.go @@ -0,0 +1,35 @@ +/* +Copyright 2020 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 + + https://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 kvstore + +import ( + "context" +) + +type Interface interface { + // Init loads the configstore from the backing store if it exists, or + // if it does not, will create an empty one. + Init(ctx context.Context) error + // Load loads the configstore from the backing store + Load(ctx context.Context) error + // Save saves the configstore to the backing store + Save(ctx context.Context) error + // Get gets the key from the KVStore into the provided value + Get(ctx context.Context, key string, value interface{}) error + // Set sets the key into the KVStore from the provided value + Set(ctx context.Context, key string, value interface{}) error +} diff --git a/vendor/knative.dev/pkg/kvstore/kvstore_cm.go b/vendor/knative.dev/pkg/kvstore/kvstore_cm.go new file mode 100644 index 00000000..c4e1a6e8 --- /dev/null +++ b/vendor/knative.dev/pkg/kvstore/kvstore_cm.go @@ -0,0 +1,123 @@ +/* +Copyright 2020 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 + + https://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. +*/ + +// Simple abstraction for storing state on a k8s ConfigMap. Very very simple +// and uses a single entry in the ConfigMap.data for storing serialized +// JSON of the generic data that Load/Save uses. Handy for things like sources +// that need to persist some state (checkpointing for example). +package kvstore + +import ( + "context" + "encoding/json" + "fmt" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/client-go/kubernetes/typed/core/v1" + "knative.dev/pkg/logging" +) + +type configMapKVStore struct { + cmClient v1.ConfigMapInterface + name string + namespace string + data map[string]string +} + +var ( + _ Interface = (*configMapKVStore)(nil) +) + +func NewConfigMapKVStore(ctx context.Context, name string, namespace string, clientset v1.CoreV1Interface) Interface { + + return &configMapKVStore{name: name, namespace: namespace, cmClient: clientset.ConfigMaps(namespace)} +} + +// Init initializes configMapKVStore either by loading or creating an empty one. +func (cs *configMapKVStore) Init(ctx context.Context) error { + l := logging.FromContext(ctx) + l.Info("Initializing configMapKVStore...") + + err := cs.Load(ctx) + if apierrors.IsNotFound(err) { + l.Info("No config found, creating empty") + return cs.createConfigMap() + } + return err +} + +// Load fetches the ConfigMap from k8s and unmarshals the data found +// in the configdatakey type as specified by value. +func (cs *configMapKVStore) Load(ctx context.Context) error { + cm, err := cs.cmClient.Get(cs.name, metav1.GetOptions{}) + if err != nil { + return err + } + cs.data = cm.Data + return nil +} + +// Save takes the value given in, and marshals it into a string +// and saves it into the k8s ConfigMap under the configdatakey. +func (cs *configMapKVStore) Save(ctx context.Context) error { + cm, err := cs.cmClient.Get(cs.name, metav1.GetOptions{}) + if err != nil { + return err + } + cm.Data = cs.data + _, err = cs.cmClient.Update(cm) + return err +} + +// Get retrieves and unmarshals the value from the map. +func (cs *configMapKVStore) Get(ctx context.Context, key string, value interface{}) error { + v, ok := cs.data[key] + if !ok { + return fmt.Errorf("key %s does not exist", key) + } + err := json.Unmarshal([]byte(v), value) + if err != nil { + return fmt.Errorf("Failed to Unmarshal %q: %v", v, err) + } + return nil +} + +// Set marshals and sets the value given under specified key. +func (cs *configMapKVStore) Set(ctx context.Context, key string, value interface{}) error { + bytes, err := json.Marshal(value) + if err != nil { + return fmt.Errorf("Failed to Marshal: %v", err) + } + cs.data[key] = string(bytes) + return nil +} + +func (cs *configMapKVStore) createConfigMap() error { + cm := &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "v1", + Kind: "ConfigMap", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: cs.name, + Namespace: cs.namespace, + }, + } + _, err := cs.cmClient.Create(cm) + return err +} diff --git a/vendor/knative.dev/test-infra/scripts/library.sh b/vendor/knative.dev/test-infra/scripts/library.sh index 3d227571..434deda2 100755 --- a/vendor/knative.dev/test-infra/scripts/library.sh +++ b/vendor/knative.dev/test-infra/scripts/library.sh @@ -482,7 +482,19 @@ function run_go_tool() { if [[ -z "$(which ${tool})" ]]; then local action=get [[ $1 =~ ^[\./].* ]] && action=install - go ${action} $1 + # Avoid running `go get` from root dir of the repository, as it can change go.sum and go.mod files. + # See discussions in https://github.com/golang/go/issues/27643. + if [[ ${action} == "get" && $(pwd) == "${REPO_ROOT_DIR}" ]]; then + local temp_dir="$(mktemp -d)" + local install_failed=0 + # Swallow the output as we are returning the stdout in the end. + pushd "${temp_dir}" > /dev/null 2>&1 + go ${action} $1 || install_failed=1 + popd > /dev/null 2>&1 + (( install_failed )) && return ${install_failed} + else + go ${action} $1 + fi fi shift 2 ${tool} "$@"