1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 14:48:55 +00:00

vendor coreos-cloudinit v1.11 (patched)

This commit is contained in:
Ivan Mikushin
2016-06-02 18:24:38 -07:00
parent 4ab3162ed8
commit bb89c44b99
26 changed files with 175 additions and 1008 deletions

View File

@@ -1,12 +1,9 @@
language: go
sudo: false
matrix:
include:
- go: 1.4
install:
- go get golang.org/x/tools/cmd/cover
- go get golang.org/x/tools/cmd/vet
- go: 1.5
env: GO15VENDOREXPERIMENT=1
- go: 1.6
script:
- ./test

View File

@@ -1,3 +1,2 @@
Alex Crawford <alex.crawford@coreos.com> (@crawford)
Jonathan Boulle <jonathan.boulle@coreos.com> (@jonboulle)
Brian Waldon <brian.waldon@coreos.com> (@bcwaldon)

View File

@@ -68,6 +68,22 @@ func NewCloudConfig(contents string) (*CloudConfig, error) {
return &cfg, err
}
// Decode decodes the content of cloud config. Currently only WriteFiles section
// supports several types of encoding and all of them are supported. After
// decode operation, Encoding type is unset.
func (cc *CloudConfig) Decode() error {
for i, file := range cc.WriteFiles {
content, err := DecodeContent(file.Content, file.Encoding)
if err != nil {
return err
}
cc.WriteFiles[i].Content = string(content)
cc.WriteFiles[i].Encoding = ""
}
return nil
}
func (cc CloudConfig) String() string {
bytes, err := yaml.Marshal(cc)
if err != nil {

View File

@@ -27,6 +27,7 @@ type Etcd2 struct {
DiscoverySRV string `yaml:"discovery_srv" env:"ETCD_DISCOVERY_SRV"`
DiscoveryProxy string `yaml:"discovery_proxy" env:"ETCD_DISCOVERY_PROXY"`
ElectionTimeout int `yaml:"election_timeout" env:"ETCD_ELECTION_TIMEOUT"`
EnablePprof bool `yaml:"enable_pprof" env:"ETCD_ENABLE_PPROF"`
ForceNewCluster bool `yaml:"force_new_cluster" env:"ETCD_FORCE_NEW_CLUSTER"`
HeartbeatInterval int `yaml:"heartbeat_interval" env:"ETCD_HEARTBEAT_INTERVAL"`
InitialAdvertisePeerURLs string `yaml:"initial_advertise_peer_urls" env:"ETCD_INITIAL_ADVERTISE_PEER_URLS"`
@@ -52,6 +53,7 @@ type Etcd2 struct {
ProxyRefreshInterval int `yaml:"proxy_refresh_interval" env:"ETCD_PROXY_REFRESH_INTERVAL"`
ProxyWriteTimeout int `yaml:"proxy_write_timeout" env:"ETCD_PROXY_WRITE_TIMEOUT"`
SnapshotCount int `yaml:"snapshot_count" env:"ETCD_SNAPSHOT_COUNT"`
StrictReconfigCheck bool `yaml:"strict_reconfig_check" env:"ETCD_STRICT_RECONFIG_CHECK"`
TrustedCAFile string `yaml:"trusted_ca_file" env:"ETCD_TRUSTED_CA_FILE"`
WalDir string `yaml:"wal_dir" env:"ETCD_WAL_DIR"`
}

View File

@@ -20,7 +20,10 @@ import (
func IsIgnitionConfig(userdata string) bool {
var cfg struct {
Version *int `json:"ignitionVersion" yaml:"ignition_version"`
Version *int `json:"ignitionVersion"`
Ignition struct {
Version *string `json:"version"`
} `json:"ignition"`
}
return (json.Unmarshal([]byte(userdata), &cfg) == nil && cfg.Version != nil)
return (json.Unmarshal([]byte(userdata), &cfg) == nil && (cfg.Version != nil || cfg.Ignition.Version != nil))
}

View File

@@ -66,7 +66,7 @@ type metadataService struct {
}
func NewDatasource(root string) *metadataService {
return &metadataService{MetadataService: metadata.NewDatasource(root, apiVersion, userdataUrl, metadataPath)}
return &metadataService{MetadataService: metadata.NewDatasource(root, apiVersion, userdataUrl, metadataPath, nil)}
}
func (ms *metadataService) FetchMetadata() (metadata datasource.Metadata, err error) {

View File

@@ -39,7 +39,7 @@ type metadataService struct {
}
func NewDatasource(root string) *metadataService {
return &metadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath)}
return &metadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath, nil)}
}
func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {

View File

@@ -0,0 +1,89 @@
// Copyright 2016 CoreOS, Inc.
//
// 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
//
// http://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 gce
import (
"fmt"
"net"
"net/http"
"github.com/coreos/coreos-cloudinit/datasource"
"github.com/coreos/coreos-cloudinit/datasource/metadata"
)
const (
apiVersion = "computeMetadata/v1/"
metadataPath = apiVersion + "instance/"
userdataPath = apiVersion + "instance/attributes/user-data"
)
type metadataService struct {
metadata.MetadataService
}
func NewDatasource(root string) *metadataService {
return &metadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath, http.Header{"Metadata-Flavor": {"Google"}})}
}
func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
public, err := ms.fetchIP("network-interfaces/0/access-configs/0/external-ip")
if err != nil {
return datasource.Metadata{}, err
}
local, err := ms.fetchIP("network-interfaces/0/ip")
if err != nil {
return datasource.Metadata{}, err
}
hostname, err := ms.fetchString("hostname")
if err != nil {
return datasource.Metadata{}, err
}
return datasource.Metadata{
PublicIPv4: public,
PrivateIPv4: local,
Hostname: hostname,
}, nil
}
func (ms metadataService) Type() string {
return "gce-metadata-service"
}
func (ms metadataService) fetchString(key string) (string, error) {
data, err := ms.FetchData(ms.MetadataUrl() + key)
if err != nil {
return "", err
}
return string(data), nil
}
func (ms metadataService) fetchIP(key string) (net.IP, error) {
str, err := ms.fetchString(key)
if err != nil {
return nil, err
}
if str == "" {
return nil, nil
}
if ip := net.ParseIP(str); ip != nil {
return ip, nil
} else {
return nil, fmt.Errorf("couldn't parse %q as IP address", str)
}
}

View File

@@ -15,6 +15,7 @@
package metadata
import (
"net/http"
"strings"
"github.com/coreos/coreos-cloudinit/pkg"
@@ -28,11 +29,11 @@ type MetadataService struct {
MetadataPath string
}
func NewDatasource(root, apiVersion, userdataPath, metadataPath string) MetadataService {
func NewDatasource(root, apiVersion, userdataPath, metadataPath string, header http.Header) MetadataService {
if !strings.HasSuffix(root, "/") {
root += "/"
}
return MetadataService{root, pkg.NewHttpClient(), apiVersion, userdataPath, metadataPath}
return MetadataService{root, pkg.NewHttpClientHeader(header), apiVersion, userdataPath, metadataPath}
}
func (ms MetadataService) IsAvailable() bool {

View File

@@ -62,7 +62,7 @@ type metadataService struct {
}
func NewDatasource(root string) *metadataService {
return &metadataService{MetadataService: metadata.NewDatasource(root, apiVersion, userdataUrl, metadataPath)}
return &metadataService{MetadataService: metadata.NewDatasource(root, apiVersion, userdataUrl, metadataPath, nil)}
}
func (ms *metadataService) FetchMetadata() (metadata datasource.Metadata, err error) {

View File

@@ -36,7 +36,16 @@ func ParseUserData(contents string) (interface{}, error) {
return config.NewScript(contents)
case config.IsCloudConfig(contents):
log.Printf("Parsing user-data as cloud-config")
return config.NewCloudConfig(contents)
cc, err := config.NewCloudConfig(contents)
if err != nil {
return nil, err
}
if err := cc.Decode(); err != nil {
return nil, err
}
return cc, nil
case config.IsIgnitionConfig(contents):
return nil, ErrIgnitionConfig
default:

View File

@@ -62,8 +62,8 @@ type HttpClient struct {
// Maximum number of connection retries. Defaults to 15
MaxRetries int
// Whether or not to skip TLS verification. Defaults to false
SkipTLS bool
// Headers to add to the request.
Header http.Header
client *http.Client
}
@@ -74,11 +74,15 @@ type Getter interface {
}
func NewHttpClient() *HttpClient {
return NewHttpClientHeader(nil)
}
func NewHttpClientHeader(header http.Header) *HttpClient {
hc := &HttpClient{
InitialBackoff: 50 * time.Millisecond,
MaxBackoff: time.Second * 5,
MaxRetries: 15,
SkipTLS: false,
Header: header,
client: &http.Client{
Timeout: 10 * time.Second,
},
@@ -139,7 +143,13 @@ func (h *HttpClient) GetRetry(rawurl string) ([]byte, error) {
}
func (h *HttpClient) Get(dataURL string) ([]byte, error) {
if resp, err := h.client.Get(dataURL); err == nil {
request, err := http.NewRequest("GET", dataURL, nil)
if err != nil {
return nil, err
}
request.Header = h.Header
if resp, err := h.client.Do(request); err == nil {
defer resp.Body.Close()
switch resp.StatusCode / 100 {
case HTTP_2xx:

View File

@@ -106,7 +106,7 @@ func WriteEnvFile(ef *EnvFile, root string) error {
// keys returns the keys of a map in sorted order
func keys(m map[string]string) (s []string) {
for k, _ := range m {
for k := range m {
s = append(s, k)
}
sort.Strings(s)

View File

@@ -45,17 +45,16 @@ func (f *File) Permissions() (os.FileMode, error) {
return os.FileMode(perm), nil
}
// WriteFile writes given endecoded file to the filesystem
func WriteFile(f *File, root string) (string, error) {
if f.Encoding != "" {
return "", fmt.Errorf("Unable to write file with encoding %s", f.Encoding)
}
fullpath := path.Join(root, f.Path)
dir := path.Dir(fullpath)
log.Printf("Writing file to %q", fullpath)
content, err := config.DecodeContent(f.Content, f.Encoding)
if err != nil {
return "", fmt.Errorf("Unable to decode %s (%v)", f.Path, err)
}
if err := EnsureDirectoryExists(dir); err != nil {
return "", err
}
@@ -71,7 +70,7 @@ func WriteFile(f *File, root string) (string, error) {
return "", err
}
if err := ioutil.WriteFile(tmp.Name(), content, perm); err != nil {
if err := ioutil.WriteFile(tmp.Name(), []byte(f.Content), perm); err != nil {
return "", err
}

View File

@@ -2,42 +2,26 @@
source ./build
SRC="
config
config/validate
datasource
datasource/configdrive
datasource/file
datasource/metadata
datasource/metadata/cloudsigma
datasource/metadata/digitalocean
datasource/metadata/ec2
datasource/proc_cmdline
datasource/test
datasource/url
datasource/vmware
datasource/waagent
initialize
network
pkg
system
.
"
SRC=$(find . -name '*.go' \
-not -path "./vendor/*")
PKG=$(cd gopath/src/${REPO_PATH}; go list ./... | \
grep --invert-match vendor)
echo "Checking gofix..."
go tool fix -diff $SRC
echo "Checking gofmt..."
gofmt -d -e $SRC
# split SRC into an array and prepend REPO_PATH to each local package for go vet
split_vet=(${SRC// / })
VET_TEST="${REPO_PATH} ${split_vet[@]/#/${REPO_PATH}/}"
res=$(gofmt -d -e -s $SRC)
echo "${res}"
if [ -n "${res}" ]; then
exit 1
fi
echo "Checking govet..."
go vet $VET_TEST
go vet $PKG
echo "Running tests..."
go test -timeout 60s -cover $@ ${VET_TEST} --race
go test -timeout 60s -cover $@ ${PKG} --race
echo "Success"

View File

@@ -0,0 +1,11 @@
# If you manipulate the contents of vendor/, amend this accordingly.
# pkg version
github.com/cloudsigma/cepgo 1bfc4895bf5c4d3b599f3f6ee142299488c8739b
github.com/coreos/go-systemd/dbus 4fbc5060a317b142e6c7bfbedb65596d5f0ab99b
github.com/coreos/yaml 6b16a5714269b2f70720a45406b1babd947a17ef
github.com/dotcloud/docker/pkg/netlink 55d41c3e21e1593b944c06196ffb2ac57ab7f653
github.com/guelfey/go.dbus f6a3a2366cc39b8479cadc499d3c735fb10fbdda
github.com/tarm/goserial cdabc8d44e8e84f58f18074ae44337e1f2f375b9
github.com/sigma/vmw-guestinfo 95dd4126d6e8b4ef1970b3f3fe2e8cdd470d2903
github.com/sigma/vmw-ovflib 56b4f44581cac03d17d8270158bdfd0942ffe790
github.com/sigma/bdoor babf2a4017b020d4ce04e8167076186e82645dd1