mirror of https://github.com/knative/caching.git
Auto-update dependencies (#73)
Produced via: `dep ensure -update knative.dev/test-infra knative.dev/pkg` /assign @mattmoor
This commit is contained in:
parent
701c8f52e8
commit
62f489e186
|
@ -927,7 +927,7 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:7d668b9ed0ede5e4a99aaed9c9f7c786920de47b2c609a88bcff96c1cd54e7da"
|
||||
digest = "1:4ad65001bd7667eebd1c0e32c4c166cad0ddbc71015195887f9942458ff19012"
|
||||
name = "knative.dev/pkg"
|
||||
packages = [
|
||||
"apis",
|
||||
|
@ -946,7 +946,7 @@
|
|||
"metrics/metricskey",
|
||||
]
|
||||
pruneopts = "T"
|
||||
revision = "057c0dfb8f56cec704b8d54c1f0517596df78a55"
|
||||
revision = "d3c17af1d97a4dd7f0167628df312f1e9889f444"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -957,7 +957,7 @@
|
|||
"tools/dep-collector",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "7fa4059a538fb5547e50f036db4e9f8d4eb998aa"
|
||||
revision = "aa17edaa3b0d03edfb5c9cba8422e8151d759fad"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
|
|
|
@ -28,6 +28,8 @@ import (
|
|||
type URL url.URL
|
||||
|
||||
// ParseURL attempts to parse the given string as a URL.
|
||||
// Compatible with net/url.Parse except in the case of an empty string, where
|
||||
// the resulting *URL will be nil with no error.
|
||||
func ParseURL(u string) (*URL, error) {
|
||||
if u == "" {
|
||||
return nil, nil
|
||||
|
|
|
@ -19,6 +19,7 @@ package v1alpha1
|
|||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
@ -35,12 +36,74 @@ type Destination struct {
|
|||
// URI is for direct URI Designations.
|
||||
URI *apis.URL `json:"uri,omitempty"`
|
||||
|
||||
// Path is used with the resulting URL from Addressable ObjectReference or
|
||||
// URI. Must start with `/`. Will be appended to the path of the resulting
|
||||
// URL from the Addressable, or URI.
|
||||
// Path is used with the resulting URL from Addressable ObjectReference or URI. Must start
|
||||
// with `/`. An empty path should be represented as the nil value, not `` or `/`. Will be
|
||||
// appended to the path of the resulting URL from the Addressable, or URI.
|
||||
Path *string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
// NewDestination constructs a Destination from an object reference as a convenience.
|
||||
func NewDestination(obj *corev1.ObjectReference, paths ...string) (*Destination, error) {
|
||||
dest := &Destination{
|
||||
ObjectReference: obj,
|
||||
}
|
||||
err := dest.AppendPath(paths...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dest, nil
|
||||
}
|
||||
|
||||
// NewDestinationURI constructs a Destination from a URI.
|
||||
func NewDestinationURI(uri *apis.URL, paths ...string) (*Destination, error) {
|
||||
dest := &Destination{
|
||||
URI: uri,
|
||||
}
|
||||
err := dest.AppendPath(paths...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dest, nil
|
||||
}
|
||||
|
||||
// AppendPath iteratively appends paths to the Destination.
|
||||
// The path will always begin with "/" unless it is empty.
|
||||
// An empty path ("" or "/") will always resolve to nil.
|
||||
func (current *Destination) AppendPath(paths ...string) error {
|
||||
// Start with empty string or existing path
|
||||
var fullpath string
|
||||
if current.Path != nil {
|
||||
fullpath = *current.Path
|
||||
}
|
||||
|
||||
// Intelligently join all the paths provided
|
||||
fullpath = path.Join("/", fullpath, path.Join(paths...))
|
||||
|
||||
// Parse the URL to trim garbage
|
||||
urlpath, err := apis.ParseURL(fullpath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// apis.ParseURL returns nil if our path was empty, then our path
|
||||
// should reflect that it is not set.
|
||||
if urlpath == nil {
|
||||
current.Path = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// A path of "/" adds no information, just toss it
|
||||
// Note that urlpath.Path == "" is always false here (joined with "/" above).
|
||||
if urlpath.Path == "/" {
|
||||
current.Path = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only use the plain path from the URL
|
||||
current.Path = &urlpath.Path
|
||||
return nil
|
||||
}
|
||||
|
||||
func (current *Destination) Validate(ctx context.Context) *apis.FieldError {
|
||||
if current != nil {
|
||||
errs := validateDestination(*current).ViaField(apis.CurrentField)
|
||||
|
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
## Test Infra 2.0 Supporting Libs
|
||||
|
||||
See [high level](https://docs.google.com/document/d/1QHPks3oRKccTpzAOJuU2tgHjyiA0Somm7PwdQVupyk0/edit#heading=h.x9snb54sjlu9) and [low level](https://docs.google.com/document/d/1PQ6DLL8kqMSSmciTSrR9RLaJt8sBgaziLEkwkP9TKec/edit#heading=h.x9snb54sjlu9) designs for more details
|
||||
See
|
||||
[high level](https://docs.google.com/document/d/1QHPks3oRKccTpzAOJuU2tgHjyiA0Somm7PwdQVupyk0/edit#heading=h.x9snb54sjlu9)
|
||||
and
|
||||
[low level](https://docs.google.com/document/d/1PQ6DLL8kqMSSmciTSrR9RLaJt8sBgaziLEkwkP9TKec/edit#heading=h.x9snb54sjlu9)
|
||||
designs for more details
|
||||
|
|
|
@ -37,8 +37,6 @@ type GKECluster struct {
|
|||
NeedCleanup bool
|
||||
// TODO: evaluate returning "google.golang.org/api/container/v1.Cluster" when implementing the creation logic
|
||||
Cluster *string
|
||||
// Exec is the function used for execute standard shell functions, return stdout and stderr
|
||||
Exec func(string, ...string) ([]byte, error)
|
||||
}
|
||||
|
||||
// Setup sets up a GKECluster client.
|
||||
|
@ -47,9 +45,7 @@ type GKECluster struct {
|
|||
// region: default to regional cluster if not provided, and use default backup regions
|
||||
// zone: default is none, must be provided together with region
|
||||
func (gs *GKEClient) Setup(numNodes *int, nodeType *string, region *string, zone *string, project *string) (ClusterOperations, error) {
|
||||
gc := &GKECluster{
|
||||
Exec: standardExec,
|
||||
}
|
||||
gc := &GKECluster{}
|
||||
// check for local run
|
||||
if nil != project { // if project is supplied, use it and create cluster
|
||||
gc.Project = project
|
||||
|
@ -102,7 +98,7 @@ func (gc *GKECluster) Delete() error {
|
|||
// if project can be derived from gcloud, sets it up as well
|
||||
func (gc *GKECluster) checkEnvironment() error {
|
||||
// if kubeconfig is configured, use it
|
||||
output, err := gc.Exec("kubectl", "config", "current-context")
|
||||
output, err := common.StandardExec("kubectl", "config", "current-context")
|
||||
if nil == err {
|
||||
// output should be in the form of gke_PROJECT_REGION_CLUSTER
|
||||
parts := strings.Split(string(output), "_")
|
||||
|
@ -119,7 +115,7 @@ func (gc *GKECluster) checkEnvironment() error {
|
|||
}
|
||||
|
||||
// if gcloud is pointing to a project, use it
|
||||
output, err = gc.Exec("gcloud", "config", "get-value", "project")
|
||||
output, err = common.StandardExec("gcloud", "config", "get-value", "project")
|
||||
if nil != err {
|
||||
return fmt.Errorf("failed getting gcloud project: '%v'", err)
|
||||
}
|
||||
|
|
|
@ -17,10 +17,37 @@ limitations under the License.
|
|||
package clustermanager
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"fmt"
|
||||
|
||||
"knative.dev/pkg/testutils/common"
|
||||
)
|
||||
|
||||
// standardExec executes shell command and returns stdout and stderr
|
||||
func standardExec(name string, args ...string) ([]byte, error) {
|
||||
return exec.Command(name, args...).Output()
|
||||
var (
|
||||
ClusterResource ResourceType = "e2e-cls"
|
||||
)
|
||||
|
||||
type ResourceType string
|
||||
|
||||
// getResourceName defines how a resource should be named based on it's
|
||||
// type, the name follows: k{reponame}-{typename} for local user, and
|
||||
// append BUILD_NUMBER with up to 20 chars. This is best effort, as it
|
||||
// shouldn't fail
|
||||
func getResourceName(rt ResourceType) (string, error) {
|
||||
var resName string
|
||||
repoName, err := common.GetRepoName()
|
||||
if nil != err {
|
||||
return "", fmt.Errorf("failed getting reponame for forming resource name: '%v'", err)
|
||||
}
|
||||
resName = fmt.Sprintf("k%s-%s", repoName, string(rt))
|
||||
if common.IsProw() {
|
||||
buildNumStr := common.GetOSEnv("BUILD_NUMBER")
|
||||
if "" == buildNumStr {
|
||||
return "", fmt.Errorf("failed getting BUILD_NUMBER env var")
|
||||
}
|
||||
if len(buildNumStr) > 20 {
|
||||
buildNumStr = string(buildNumStr[:20])
|
||||
}
|
||||
resName = fmt.Sprintf("%s-%s", resName, buildNumStr)
|
||||
}
|
||||
return resName, nil
|
||||
}
|
||||
|
|
|
@ -16,8 +16,36 @@ limitations under the License.
|
|||
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// GetOSEnv is for easier mocking in unit tests
|
||||
GetOSEnv = os.Getenv
|
||||
// StandardExec is for easier mocking in unit tests
|
||||
StandardExec = standardExec
|
||||
)
|
||||
|
||||
// standardExec executes shell command and returns stdout and stderr
|
||||
func standardExec(name string, args ...string) ([]byte, error) {
|
||||
return exec.Command(name, args...).Output()
|
||||
}
|
||||
|
||||
// IsProw checks if the process is initialized by Prow
|
||||
func IsProw() bool {
|
||||
// TODO: Implement
|
||||
return false
|
||||
return "" != GetOSEnv("PROW_JOB_ID")
|
||||
}
|
||||
|
||||
// GetRepoName gets repo name by the path where the repo cloned to
|
||||
func GetRepoName() (string, error) {
|
||||
out, err := StandardExec("git", "rev-parse", "--show-toplevel")
|
||||
if nil != err {
|
||||
return "", fmt.Errorf("failed git rev-parse --show-toplevel: '%v'", err)
|
||||
}
|
||||
return strings.TrimSpace(path.Base(string(out))), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue