ref(*): kubernetes v1.8 support

parent 3410a690
......@@ -239,16 +239,16 @@ func getKubeClient(context string) (*rest.Config, kubernetes.Interface, error) {
// getInternalKubeClient creates a Kubernetes config and an "internal" client for a given kubeconfig context.
//
// Prefer the similar getKubeClient if you don't need to use such an internal client.
func getInternalKubeClient(context string) (*rest.Config, internalclientset.Interface, error) {
func getInternalKubeClient(context string) (internalclientset.Interface, error) {
config, err := configForContext(context)
if err != nil {
return nil, nil, err
return nil, err
}
client, err := internalclientset.NewForConfig(config)
if err != nil {
return nil, nil, fmt.Errorf("could not get Kubernetes client: %s", err)
return nil, fmt.Errorf("could not get Kubernetes client: %s", err)
}
return config, client, nil
return client, nil
}
// ensureHelmClient returns a new helm client impl. if h is not nil.
......
......@@ -27,12 +27,12 @@ import (
"github.com/ghodss/yaml"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
testcore "k8s.io/client-go/testing"
"encoding/json"
......
......@@ -22,14 +22,14 @@ import (
"strings"
"github.com/ghodss/yaml"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
extensionsclient "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
"k8s.io/helm/pkg/chartutil"
)
......
......@@ -23,11 +23,11 @@ import (
"testing"
"github.com/ghodss/yaml"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
testcore "k8s.io/client-go/testing"
"k8s.io/helm/pkg/chartutil"
......
......@@ -19,7 +19,7 @@ package installer // import "k8s.io/helm/cmd/helm/installer"
import (
"fmt"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/api/core/v1"
"k8s.io/helm/pkg/strvals"
"k8s.io/helm/pkg/version"
)
......
......@@ -19,7 +19,7 @@ package installer // import "k8s.io/helm/cmd/helm/installer"
import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
"k8s.io/kubernetes/pkg/kubectl"
......
......@@ -86,7 +86,7 @@ func newResetCmd(client helm.Interface, out io.Writer) *cobra.Command {
// runReset uninstalls tiller from Kubernetes Cluster and deletes local config
func (d *resetCmd) run() error {
if d.kubeClient == nil {
_, c, err := getInternalKubeClient(settings.KubeContext)
c, err := getInternalKubeClient(settings.KubeContext)
if err != nil {
return fmt.Errorf("could not get kubernetes client: %s", err)
}
......
This diff is collapsed.
......@@ -28,7 +28,7 @@ import:
- package: google.golang.org/grpc
version: 1.2.1
- package: k8s.io/kubernetes
version: ~1.7.0
version: ~1.8.0
- package: github.com/gosuri/uitable
- package: github.com/asaskevich/govalidator
version: ^4.0.0
......@@ -48,37 +48,7 @@ import:
- package: vbom.ml/util
repo: https://github.com/fvbommel/util.git
vcs: git
- package: github.com/docker/distribution
version: ~2.4.0
# hacks for kubernetes v1.7
- package: cloud.google.com/go
- package: github.com/Azure/go-autorest
version: v8.0.0
- package: github.com/dgrijalva/jwt-go
- package: github.com/docker/spdystream
- package: github.com/go-openapi/analysis
version: b44dc874b601d9e4e2f6e19140e794ba24bead3b
- package: github.com/go-openapi/errors
version: d24ebc2075bad502fac3a8ae27aa6dd58e1952dc
- package: github.com/go-openapi/loads
version: 18441dfa706d924a39a030ee2c3b1d8d81917b38
- package: github.com/go-openapi/spec
version: 6aced65f8501fe1217321abf0749d354824ba2ff
- package: github.com/google/gofuzz
- package: github.com/hashicorp/golang-lru
- package: github.com/howeyc/gopass
- package: github.com/juju/ratelimit
version: 5b9ff866471762aa2ab2dced63c9fb6f53921342
- package: github.com/pborman/uuid
- package: golang.org/x/oauth2
- package: gopkg.in/inf.v0
- package: github.com/go-openapi/strfmt
- package: github.com/mitchellh/mapstructure
- package: gopkg.in/mgo.v2/bson
ignore:
- k8s.io/client-go
- k8s.io/apimachinery
testImports:
- package: github.com/stretchr/testify
version: ^1.1.4
......
......@@ -17,7 +17,7 @@ limitations under the License.
package portforwarder
import (
"k8s.io/client-go/pkg/api/v1"
"k8s.io/api/core/v1"
)
// These functions are adapted from the "kubernetes" repository's file
......
......@@ -19,11 +19,11 @@ package portforwarder
import (
"fmt"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/rest"
"k8s.io/helm/pkg/kube"
......
......@@ -19,9 +19,9 @@ package portforwarder
import (
"testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/pkg/api/v1"
)
func mockTillerPod() v1.Pod {
......
......@@ -27,6 +27,10 @@ import (
"time"
jsonpatch "github.com/evanphx/json-patch"
apps "k8s.io/api/apps/v1beta2"
batch "k8s.io/api/batch/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
......@@ -40,15 +44,12 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/helper"
"k8s.io/kubernetes/pkg/api/v1"
apps "k8s.io/kubernetes/pkg/apis/apps/v1beta1"
batchinternal "k8s.io/kubernetes/pkg/apis/batch"
batch "k8s.io/kubernetes/pkg/apis/batch/v1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
conditions "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/printers"
)
......@@ -103,13 +104,9 @@ func (c *Client) Create(namespace string, reader io.Reader, timeout int64, shoul
}
func (c *Client) newBuilder(namespace string, reader io.Reader) *resource.Result {
schema, err := c.Validator(true, c.SchemaCacheDir)
if err != nil {
c.Log("warning: failed to load schema: %s", err)
}
return c.NewBuilder(true).
ContinueOnError().
Schema(schema).
Schema(c.validator()).
NamespaceParam(namespace).
DefaultNamespace().
Stream(reader, "").
......@@ -117,20 +114,25 @@ func (c *Client) newBuilder(namespace string, reader io.Reader) *resource.Result
Do()
}
// BuildUnstructured validates for Kubernetes objects and returns unstructured infos.
func (c *Client) BuildUnstructured(namespace string, reader io.Reader) (Result, error) {
schema, err := c.Validator(true, c.SchemaCacheDir)
func (c *Client) validator() validation.Schema {
const openapi = false // only works on v1.8 clusters
schema, err := c.Validator(true, openapi, c.SchemaCacheDir)
if err != nil {
c.Log("warning: failed to load schema: %s", err)
}
return schema
}
// BuildUnstructured validates for Kubernetes objects and returns unstructured infos.
func (c *Client) BuildUnstructured(namespace string, reader io.Reader) (Result, error) {
var result Result
b, err := c.NewUnstructuredBuilder(true)
if err != nil {
return result, err
}
result, err = b.ContinueOnError().
Schema(schema).
Schema(c.validator()).
NamespaceParam(namespace).
DefaultNamespace().
Stream(reader, "").
......
......@@ -35,11 +35,11 @@ import (
"k8s.io/client-go/rest/fake"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/kubectl"
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/printers"
watchjson "k8s.io/kubernetes/pkg/watch/json"
)
......
......@@ -21,11 +21,12 @@ import (
"io"
"io/ioutil"
"net"
"net/http"
"strconv"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/portforward"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/client-go/transport/spdy"
)
// Tunnel describes a ssh-like tunnel to a kubernetes pod
......@@ -71,10 +72,11 @@ func (t *Tunnel) ForwardPort() error {
Name(t.PodName).
SubResource("portforward").URL()
dialer, err := remotecommand.NewExecutor(t.config, "POST", u)
transport, upgrader, err := spdy.RoundTripperFor(t.config)
if err != nil {
return err
}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", u)
local, err := getAvailablePort()
if err != nil {
......
......@@ -19,20 +19,18 @@ package kube // import "k8s.io/helm/pkg/kube"
import (
"time"
appsv1beta1 "k8s.io/api/apps/v1beta1"
appsv1beta2 "k8s.io/api/apps/v1beta2"
"k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/api/v1/helper"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
apps "k8s.io/kubernetes/pkg/apis/apps/v1beta1"
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
core "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1"
extensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/extensions/v1beta1"
internalclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
)
......@@ -47,11 +45,10 @@ type deployment struct {
func (c *Client) waitForResources(timeout time.Duration, created Result) error {
c.Log("beginning wait for %d resources with timeout of %v", len(created), timeout)
cs, err := c.ClientSet()
kcs, err := c.KubernetesClientSet()
if err != nil {
return err
}
client := versionedClientsetForDeployment(cs)
return wait.Poll(2*time.Second, timeout, func() (bool, error) {
pods := []v1.Pod{}
services := []v1.Service{}
......@@ -64,24 +61,24 @@ func (c *Client) waitForResources(timeout time.Duration, created Result) error {
}
switch value := obj.(type) {
case (*v1.ReplicationController):
list, err := getPods(client, value.Namespace, value.Spec.Selector)
list, err := getPods(kcs, value.Namespace, value.Spec.Selector)
if err != nil {
return false, err
}
pods = append(pods, list...)
case (*v1.Pod):
pod, err := client.Core().Pods(value.Namespace).Get(value.Name, metav1.GetOptions{})
pod, err := kcs.Core().Pods(value.Namespace).Get(value.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
pods = append(pods, *pod)
case (*extensions.Deployment):
currentDeployment, err := client.Extensions().Deployments(value.Namespace).Get(value.Name, metav1.GetOptions{})
currentDeployment, err := kcs.Extensions().Deployments(value.Namespace).Get(value.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
// Find RS associated with deployment
newReplicaSet, err := deploymentutil.GetNewReplicaSet(currentDeployment, client)
newReplicaSet, err := deploymentutil.GetNewReplicaSet(currentDeployment, kcs.ExtensionsV1beta1())
if err != nil || newReplicaSet == nil {
return false, err
}
......@@ -91,31 +88,37 @@ func (c *Client) waitForResources(timeout time.Duration, created Result) error {
}
deployments = append(deployments, newDeployment)
case (*extensions.DaemonSet):
list, err := getPods(client, value.Namespace, value.Spec.Selector.MatchLabels)
list, err := getPods(kcs, value.Namespace, value.Spec.Selector.MatchLabels)
if err != nil {
return false, err
}
pods = append(pods, list...)
case (*apps.StatefulSet):
list, err := getPods(client, value.Namespace, value.Spec.Selector.MatchLabels)
case (*appsv1beta1.StatefulSet):
list, err := getPods(kcs, value.Namespace, value.Spec.Selector.MatchLabels)
if err != nil {
return false, err
}
pods = append(pods, list...)
case (*appsv1beta2.StatefulSet):
list, err := getPods(kcs, value.Namespace, value.Spec.Selector.MatchLabels)
if err != nil {
return false, err
}
pods = append(pods, list...)
case (*extensions.ReplicaSet):
list, err := getPods(client, value.Namespace, value.Spec.Selector.MatchLabels)
list, err := getPods(kcs, value.Namespace, value.Spec.Selector.MatchLabels)
if err != nil {
return false, err
}
pods = append(pods, list...)
case (*v1.PersistentVolumeClaim):
claim, err := client.Core().PersistentVolumeClaims(value.Namespace).Get(value.Name, metav1.GetOptions{})
claim, err := kcs.Core().PersistentVolumeClaims(value.Namespace).Get(value.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
pvc = append(pvc, *claim)
case (*v1.Service):
svc, err := client.Core().Services(value.Namespace).Get(value.Name, metav1.GetOptions{})
svc, err := kcs.Core().Services(value.Namespace).Get(value.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
......@@ -178,20 +181,10 @@ func (c *Client) deploymentsReady(deployments []deployment) bool {
return true
}
func getPods(client clientset.Interface, namespace string, selector map[string]string) ([]v1.Pod, error) {
func getPods(client kubernetes.Interface, namespace string, selector map[string]string) ([]v1.Pod, error) {
list, err := client.Core().Pods(namespace).List(metav1.ListOptions{
FieldSelector: fields.Everything().String(),
LabelSelector: labels.Set(selector).AsSelector().String(),
})
return list.Items, err
}
func versionedClientsetForDeployment(internalClient internalclientset.Interface) clientset.Interface {
if internalClient == nil {
return &clientset.Clientset{}
}
return &clientset.Clientset{
CoreV1Client: core.New(internalClient.Core().RESTClient()),
ExtensionsV1beta1Client: extensionsclient.New(internalClient.Extensions().RESTClient()),
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment