diff --git a/glide.lock b/glide.lock index f73ce1e65..c95060074 100644 --- a/glide.lock +++ b/glide.lock @@ -1,28 +1,177 @@ -hash: 23af9670ae8c1600f0f3c70bd9191e0df9211fed1e57430160aed95d5c71c2d1 -updated: 2016-04-20T17:16:04.782839628-06:00 +hash: 78e69db1e2c08b4c326c61c47d602ccb5d0d4a782e5047a460e984d0c22f43a3 +updated: 2016-04-27T13:31:53.384640094-07:00 imports: +- name: bitbucket.org/ww/goautoneg + version: 75cd24fc2f2c - name: github.com/aokoli/goutils version: 9c37978a95bd5c709a15883b6242714ea6709e64 +- name: github.com/beorn7/perks + version: b965b613227fddccbfffe13eae360ed3fa822f8d + subpackages: + - quantile +- name: github.com/blang/semver + version: 31b736133b98f26d5e078ec9eb591666edfd091f - name: github.com/BurntSushi/toml version: bbd5bb678321a0d6e58f1099321dfa73391c1b6f +- name: github.com/davecgh/go-spew + version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d + subpackages: + - spew +- name: github.com/docker/distribution + version: 55f1b7651f6242617133312ff8af5c2e4e3628ea + subpackages: + - digest + - reference +- name: github.com/docker/docker + version: 0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d + subpackages: + - pkg/jsonmessage + - pkg/mount + - pkg/stdcopy + - pkg/symlink + - pkg/term + - pkg/timeutils + - pkg/units +- name: github.com/docker/engine-api + version: 26cdffeca716ae4df98070051a852b3198d7d153 + subpackages: + - client + - types + - types/container + - types/filters + - types/network + - types/registry + - types/blkiodev + - types/strslice +- name: github.com/docker/go-connections + version: f549a9393d05688dff0992ef3efd8bbe6c628aeb + subpackages: + - nat + - sockets + - tlsconfig +- name: github.com/docker/go-units + version: 0bbddae09c5a5419a8c6dcdd7ff90da3d450393b +- name: github.com/emicklei/go-restful + version: 496d495156da218b9912f03dfa7df7f80fbd8cc3 + subpackages: + - swagger + - log +- name: github.com/evanphx/json-patch + version: 7dd4489c2eb6073e5a9d7746c3274c5b5f0387df +- name: github.com/ghodss/yaml + version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee +- name: github.com/gogo/protobuf + version: 82d16f734d6d871204a3feb1a73cb220cc92574c + subpackages: + - gogoproto + - plugin/defaultcheck + - plugin/description + - plugin/embedcheck + - plugin/enumstringer + - plugin/equal + - plugin/face + - plugin/gostring + - plugin/grpc + - plugin/marshalto + - plugin/oneofcheck + - plugin/populate + - plugin/size + - plugin/stringer + - plugin/testgen + - plugin/union + - plugin/unmarshal + - proto + - protoc-gen-gogo/descriptor + - protoc-gen-gogo/generator + - protoc-gen-gogo/plugin + - sortkeys + - vanity +- name: github.com/golang/glog + version: 44145f04b68cf362d9c4df2182967c2275eaefed +- name: github.com/golang/groupcache + version: 604ed5785183e59ae2789449d89e73f3a2a77987 + subpackages: + - lru - name: github.com/golang/protobuf version: f0a097ddac24fb00e07d2ac17f8671423f3ea47c subpackages: - proto - ptypes/any - ptypes/timestamp +- name: github.com/google/cadvisor + version: 546a3771589bdb356777c646c6eca24914fdd48b + subpackages: + - api + - cache/memory + - collector + - container + - events + - fs + - healthz + - http + - info/v1 + - info/v2 + - manager + - metrics + - pages + - storage + - summary + - utils + - validate + - version +- name: github.com/google/gofuzz + version: bbcb9da2d746f8bdbd6a936686a0a6067ada0ec5 +- name: github.com/imdario/mergo + version: 6633656539c1639d9d78127b7d47c622b5d7b6dc +- name: github.com/inconshreveable/mousetrap + version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 +- name: github.com/juju/ratelimit + version: 77ed1c8a01217656d2080ad51981f6e99adaa177 - name: github.com/Masterminds/semver version: 808ed7761c233af2de3f9729a041d68c62527f3a - name: github.com/Masterminds/sprig - version: 679bb747f11c6ffc3373965988fea8877c40b47b + version: e6494bc7e81206ba6db404d2fd96500ffc453407 +- name: github.com/matttproud/golang_protobuf_extensions + version: fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a + subpackages: + - pbutil +- name: github.com/opencontainers/runc + version: 7ca2aa4873aea7cb4265b1726acb24b90d8726c6 + subpackages: + - libcontainer + - libcontainer/cgroups/fs + - libcontainer/configs + - libcontainer/cgroups + - libcontainer/system +- name: github.com/pborman/uuid + version: ca53cad383cad2479bbba7f7a1a05797ec1386e4 +- name: github.com/prometheus/client_golang + version: 3b78d7a77f51ccbc364d4bc170920153022cfd08 + subpackages: + - prometheus +- name: github.com/prometheus/client_model + version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6 + subpackages: + - go +- name: github.com/prometheus/common + version: ef7a9a5fb138aa5d3a19988537606226869a0390 + subpackages: + - expfmt + - model +- name: github.com/prometheus/procfs + version: 490cc6eb5fa45bf8a8b7b73c8bc82a8160e8531d - name: github.com/spf13/cobra - version: 4c05eb1145f16d0e6bb4a3e1b6d769f4713cb41f + version: e14e47b7a916ed178f4559ebd7e625cf16410181 subpackages: - cobra - name: github.com/spf13/pflag - version: 8f6a28b0916586e7f22fe931ae2fcfc380b1c0e6 + version: cb88ea77998c3f024757528e3305022ab50b43be - name: github.com/technosophos/moniker version: 9f956786b91d9786ca11aa5be6104542fa911546 +- name: github.com/ugorji/go + version: f4485b318aadd133842532f841dc205a8e339d74 + subpackages: + - codec - name: golang.org/x/net version: fb93926129b8ec0056f2f458b1f519654814edf0 subpackages: @@ -31,6 +180,31 @@ imports: - trace - http2/hpack - internal/timeseries + - context/ctxhttp +- name: golang.org/x/oauth2 + version: b5adcc2dcdf009d0391547edc6ecbaff889f5bb9 + subpackages: + - google + - internal + - jwt + - jws +- name: google.golang.org/appengine + version: 12d5545dc1cfa6047a286d5e853841b6471f4c19 + subpackages: + - internal + - internal/app_identity + - internal/base + - internal/datastore + - internal/log + - internal/modules + - internal/remote_api + - urlfetch + - internal/urlfetch +- name: google.golang.org/cloud + version: eb47ba841d53d93506cfbfbc03927daf9cc48f88 + subpackages: + - compute/metadata + - internal - name: google.golang.org/grpc version: dec33edc378cf4971a2741cfd86ed70a644d6ba3 subpackages: @@ -44,4 +218,131 @@ imports: - peer - name: gopkg.in/yaml.v2 version: a83829b6f1293c91addabc89d0571c246397bbf4 +- name: k8s.io/heapster + version: 0991ac528ea24aae194e45d6dcf01896cb42cbea + subpackages: + - api/v1/types +- name: k8s.io/kubernetes + version: 95f2ca2ff65a03342746a2a49b8f360428dd94a2 + subpackages: + - pkg/client/unversioned/clientcmd + - pkg/kubectl/cmd/util + - pkg/kubectl/resource + - pkg/api + - pkg/api/unversioned + - pkg/client/restclient + - pkg/client/unversioned/auth + - pkg/client/unversioned/clientcmd/api + - pkg/client/unversioned/clientcmd/api/latest + - pkg/runtime + - pkg/util/errors + - pkg/util/homedir + - pkg/util/validation + - pkg/api/errors + - pkg/api/meta + - pkg/api/validation + - pkg/apimachinery + - pkg/apimachinery/registered + - pkg/apis/apps + - pkg/apis/autoscaling + - pkg/apis/batch + - pkg/apis/extensions + - pkg/apis/metrics + - pkg/client/typed/discovery + - pkg/client/unversioned + - pkg/client/unversioned/adapters/internalclientset + - pkg/kubectl + - pkg/labels + - pkg/registry/thirdpartyresourcedata + - pkg/runtime/serializer/json + - pkg/util/flag + - pkg/util/strategicpatch + - pkg/util/sets + - pkg/util/yaml + - pkg/watch + - pkg/api/resource + - pkg/auth/user + - pkg/conversion + - pkg/fields + - pkg/runtime/serializer + - pkg/types + - pkg/util + - pkg/util/intstr + - pkg/util/rand + - pkg/api/v1 + - pkg/client/metrics + - pkg/client/transport + - pkg/util/crypto + - pkg/util/flowcontrol + - pkg/util/net + - pkg/version + - pkg/watch/json + - pkg/client/unversioned/clientcmd/api/v1 + - pkg/runtime/serializer/versioning + - pkg/conversion/queryparams + - pkg/util/json + - pkg/util/validation/field + - pkg/api/endpoints + - pkg/api/pod + - pkg/api/service + - pkg/api/util + - pkg/capabilities + - pkg/api/install + - pkg/apis/apps/install + - pkg/apis/authorization/install + - pkg/apis/autoscaling/install + - pkg/apis/batch/install + - pkg/apis/componentconfig/install + - pkg/apis/extensions/install + - pkg/apis/metrics/install + - pkg/util/wait + - plugin/pkg/client/auth + - pkg/client/clientset_generated/internalclientset + - pkg/client/clientset_generated/internalclientset/typed/core/unversioned + - pkg/client/clientset_generated/internalclientset/typed/extensions/unversioned + - pkg/apis/batch/v1 + - pkg/credentialprovider + - pkg/fieldpath + - pkg/kubelet/qos/util + - pkg/util/deployment + - pkg/util/integer + - pkg/util/jsonpath + - pkg/api/rest + - pkg/apis/extensions/v1beta1 + - pkg/apis/extensions/validation + - pkg/registry/generic + - pkg/util/framer + - third_party/forked/json + - pkg/util/runtime + - third_party/forked/reflect + - pkg/runtime/serializer/protobuf + - pkg/runtime/serializer/recognizer + - pkg/util/parsers + - pkg/watch/versioned + - pkg/util/hash + - pkg/util/net/sets + - pkg/apis/apps/v1alpha1 + - pkg/apis/authorization + - pkg/apis/authorization/v1beta1 + - pkg/apis/autoscaling/v1 + - pkg/apis/componentconfig + - pkg/apis/componentconfig/v1alpha1 + - pkg/apis/metrics/v1alpha1 + - plugin/pkg/client/auth/gcp + - pkg/client/clientset_generated/internalclientset/typed/batch/unversioned + - pkg/controller + - pkg/util/labels + - pkg/util/pod + - third_party/golang/template + - pkg/api/unversioned/validation + - pkg/controller/podautoscaler + - pkg/storage + - pkg/kubelet/qos + - pkg/master/ports + - pkg/client/cache + - pkg/client/record + - pkg/controller/framework + - pkg/controller/podautoscaler/metrics +- name: speter.net/go/exp/math/dec/inf + version: 42ca6cd68aa922bc3f32f1e056e61b65945d9ad7 devImports: [] diff --git a/glide.yaml b/glide.yaml index 962fb5aee..d150d3442 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,6 +1,7 @@ package: github.com/deis/tiller import: - package: golang.org/x/net + version: fb93926129b8ec0056f2f458b1f519654814edf0 subpackages: - context - package: github.com/spf13/cobra @@ -12,8 +13,19 @@ import: - package: github.com/Masterminds/semver version: 1.1.0 - package: github.com/BurntSushi/toml + version: bbd5bb678321a0d6e58f1099321dfa73391c1b6f - package: github.com/technosophos/moniker - package: github.com/golang/protobuf version: f0a097ddac24fb00e07d2ac17f8671423f3ea47c + subpackages: + - proto + - ptypes/any + - ptypes/timestamp - package: google.golang.org/grpc version: dec33edc378cf4971a2741cfd86ed70a644d6ba3 +- package: k8s.io/kubernetes + version: ^1.2 + subpackages: + - pkg/client/unversioned/clientcmd + - pkg/kubectl/cmd/util + - pkg/kubectl/resource diff --git a/pkg/kube/client.go b/pkg/kube/client.go new file mode 100644 index 000000000..7f6acf029 --- /dev/null +++ b/pkg/kube/client.go @@ -0,0 +1,64 @@ +package kube + +import ( + "fmt" + "io" + + "k8s.io/kubernetes/pkg/client/unversioned/clientcmd" + cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + "k8s.io/kubernetes/pkg/kubectl/resource" +) + +const includeThirdPartyAPIs = false + +// ResourceActorFunc performs an action on a signle resource. +type ResourceActorFunc func(*resource.Info) error + +// Create creates kubernetes resources from an io.reader +// +// Namespace will set the namespace +// Config allows for overiding values from kubectl +func Create(namespace string, reader io.Reader, config clientcmd.ClientConfig) error { + f := cmdutil.NewFactory(config) + return perform(f, namespace, reader, createResource) +} + +func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error { + r := f.NewBuilder(includeThirdPartyAPIs). + ContinueOnError(). + NamespaceParam(namespace). + RequireNamespace(). + Stream(reader, ""). + Flatten(). + Do() + + if r.Err() != nil { + return r.Err() + } + + count := 0 + err := r.Visit(func(info *resource.Info, err error) error { + if err != nil { + return err + } + err = fn(info) + + if err == nil { + count++ + } + return err + }) + + if err != nil { + return err + } + if count == 0 { + return fmt.Errorf("no objects passed to create") + } + return nil +} + +func createResource(info *resource.Info) error { + _, err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, info.Object) + return err +} diff --git a/pkg/kube/client_test.go b/pkg/kube/client_test.go new file mode 100644 index 000000000..daeb3dee4 --- /dev/null +++ b/pkg/kube/client_test.go @@ -0,0 +1,44 @@ +package kube + +import ( + "os" + "testing" + + "k8s.io/kubernetes/pkg/api/meta" + "k8s.io/kubernetes/pkg/client/unversioned/fake" + cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + "k8s.io/kubernetes/pkg/kubectl/resource" +) + +func TestPerform(t *testing.T) { + input, err := os.Open("./testdata/guestbook-all-in-one.yaml") + if err != nil { + t.Fatal(err) + } + defer input.Close() + + results := []*resource.Info{} + + fn := func(info *resource.Info) error { + results = append(results, info) + + if info.Namespace != "test" { + t.Errorf("expected namespace to be 'test', got %s", info.Namespace) + } + + return nil + } + + f := cmdutil.NewFactory(nil) + f.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) { + return &fake.RESTClient{}, nil + } + + if err := perform(f, "test", input, fn); err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + if len(results) != 6 { + t.Errorf("expected 6 result objects, got %d", len(results)) + } +} diff --git a/pkg/kube/testdata/guestbook-all-in-one.yaml b/pkg/kube/testdata/guestbook-all-in-one.yaml new file mode 100644 index 000000000..c6675e0eb --- /dev/null +++ b/pkg/kube/testdata/guestbook-all-in-one.yaml @@ -0,0 +1,179 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis-master + labels: + app: redis + tier: backend + role: master +spec: + ports: + # the port that this service should serve on + - port: 6379 + targetPort: 6379 + selector: + app: redis + tier: backend + role: master +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: redis-master + # these labels can be applied automatically + # from the labels in the pod template if not set + # labels: + # app: redis + # role: master + # tier: backend +spec: + # this replicas value is default + # modify it according to your case + replicas: 1 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # matchLabels: + # app: guestbook + # role: master + # tier: backend + template: + metadata: + labels: + app: redis + role: master + tier: backend + spec: + containers: + - name: master + image: gcr.io/google_containers/redis:e2e # or just image: redis + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-slave + labels: + app: redis + tier: backend + role: slave +spec: + ports: + # the port that this service should serve on + - port: 6379 + selector: + app: redis + tier: backend + role: slave +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: redis-slave + # these labels can be applied automatically + # from the labels in the pod template if not set + # labels: + # app: redis + # role: slave + # tier: backend +spec: + # this replicas value is default + # modify it according to your case + replicas: 2 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # matchLabels: + # app: guestbook + # role: slave + # tier: backend + template: + metadata: + labels: + app: redis + role: slave + tier: backend + spec: + containers: + - name: slave + image: gcr.io/google_samples/gb-redisslave:v1 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access an environment variable to find the master + # service's host, comment out the 'value: dns' line above, and + # uncomment the line below. + # value: env + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend + labels: + app: guestbook + tier: frontend +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + # type: LoadBalancer + ports: + # the port that this service should serve on + - port: 80 + selector: + app: guestbook + tier: frontend +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: frontend + # these labels can be applied automatically + # from the labels in the pod template if not set + # labels: + # app: guestbook + # tier: frontend +spec: + # this replicas value is default + # modify it according to your case + replicas: 3 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # matchLabels: + # app: guestbook + # tier: frontend + template: + metadata: + labels: + app: guestbook + tier: frontend + spec: + containers: + - name: php-redis + image: gcr.io/google-samples/gb-frontend:v4 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access environment variables to find service host + # info, comment out the 'value: dns' line above, and uncomment the + # line below. + # value: env + ports: + - containerPort: 80