Update go dependencies

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-01-26 10:24:11 -03:00
parent 2f8cbeb8fa
commit 23e7565ebc
396 changed files with 57233 additions and 47523 deletions

View file

@ -17,23 +17,27 @@ limitations under the License.
package envtest
import (
"bufio"
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/ghodss/yaml"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/rest"
"sigs.k8s.io/yaml"
)
// CRDInstallOptions are the options for installing CRDs
type CRDInstallOptions struct {
// Paths is the path to the directory containing CRDs
// Paths is a list of paths to the directories containing CRDs
Paths []string
// CRDs is a list of CRDs to install
@ -42,11 +46,11 @@ type CRDInstallOptions struct {
// ErrorIfPathMissing will cause an error if a Path does not exist
ErrorIfPathMissing bool
// maxTime is the max time to wait
maxTime time.Duration
// MaxTime is the max time to wait
MaxTime time.Duration
// pollInterval is the interval to check
pollInterval time.Duration
// PollInterval is the interval to check
PollInterval time.Duration
}
const defaultPollInterval = 100 * time.Millisecond
@ -93,11 +97,11 @@ func readCRDFiles(options *CRDInstallOptions) error {
// defaultCRDOptions sets the default values for CRDs
func defaultCRDOptions(o *CRDInstallOptions) {
if o.maxTime == 0 {
o.maxTime = defaultMaxWait
if o.MaxTime == 0 {
o.MaxTime = defaultMaxWait
}
if o.pollInterval == 0 {
o.pollInterval = defaultPollInterval
if o.PollInterval == 0 {
o.PollInterval = defaultPollInterval
}
}
@ -106,18 +110,29 @@ func WaitForCRDs(config *rest.Config, crds []*apiextensionsv1beta1.CustomResourc
// Add each CRD to a map of GroupVersion to Resource
waitingFor := map[schema.GroupVersion]*sets.String{}
for _, crd := range crds {
gv := schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version}
if _, found := waitingFor[gv]; !found {
// Initialize the set
waitingFor[gv] = &sets.String{}
gvs := []schema.GroupVersion{}
if crd.Spec.Version != "" {
gvs = append(gvs, schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version})
}
for _, ver := range crd.Spec.Versions {
if ver.Served {
gvs = append(gvs, schema.GroupVersion{Group: crd.Spec.Group, Version: ver.Name})
}
}
for _, gv := range gvs {
log.V(1).Info("adding API in waitlist", "GV", gv)
if _, found := waitingFor[gv]; !found {
// Initialize the set
waitingFor[gv] = &sets.String{}
}
// Add the Resource
waitingFor[gv].Insert(crd.Spec.Names.Plural)
}
// Add the Resource
waitingFor[gv].Insert(crd.Spec.Names.Plural)
}
// Poll until all resources are found in discovery
p := &poller{config: config, waitingFor: waitingFor}
return wait.PollImmediate(options.pollInterval, options.maxTime, p.poll)
return wait.PollImmediate(options.PollInterval, options.MaxTime, p.poll)
}
// poller checks if all the resources have been found in discovery, and returns false if not
@ -174,7 +189,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1beta1.CustomResource
// Create each CRD
for _, crd := range crds {
log.V(1).Info("installing CRD", "crd", crd)
log.V(1).Info("installing CRD", "crd", crd.Name)
if _, err := cs.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil {
return err
}
@ -202,23 +217,52 @@ func readCRDs(path string) ([]*apiextensionsv1beta1.CustomResourceDefinition, er
continue
}
// Unmarshal the file into a struct
b, err := ioutil.ReadFile(filepath.Join(path, file.Name()))
// Unmarshal CRDs from file into structs
docs, err := readDocuments(filepath.Join(path, file.Name()))
if err != nil {
return nil, err
}
crd := &apiextensionsv1beta1.CustomResourceDefinition{}
if err = yaml.Unmarshal(b, crd); err != nil {
return nil, err
for _, doc := range docs {
crd := &apiextensionsv1beta1.CustomResourceDefinition{}
if err = yaml.Unmarshal(doc, crd); err != nil {
return nil, err
}
// Check that it is actually a CRD
if crd.Spec.Names.Kind == "" || crd.Spec.Group == "" {
continue
}
crds = append(crds, crd)
}
// Check that it is actually a CRD
if crd.Spec.Names.Kind == "" || crd.Spec.Group == "" {
continue
}
log.V(1).Info("read CRD from file", "file", file)
crds = append(crds, crd)
log.V(1).Info("read CRDs from file", "file", file.Name())
}
return crds, nil
}
// readDocuments reads documents from file
func readDocuments(fp string) ([][]byte, error) {
b, err := ioutil.ReadFile(fp)
if err != nil {
return nil, err
}
docs := [][]byte{}
reader := k8syaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(b)))
for {
// Read document
doc, err := reader.Read()
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
docs = append(docs, doc)
}
return docs, nil
}