use kubernetes client-go from master branch o_O

This commit is contained in:
Murat Kabilov
2017-05-22 11:34:20 +02:00
parent d9b0ee9198
commit 614c270c55
17 changed files with 155 additions and 297 deletions
+2 -2
View File
@@ -26,8 +26,8 @@ type Config struct {
type Controller struct {
Config
opConfig *config.Config
logger *logrus.Entry
opConfig *config.Config
logger *logrus.Entry
clustersMu sync.RWMutex
clusters map[spec.NamespacedName]*cluster.Cluster
+3 -3
View File
@@ -4,9 +4,10 @@ import (
"bytes"
"fmt"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
remotecommandconsts "k8s.io/apimachinery/pkg/util/remotecommand"
"k8s.io/client-go/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned/remotecommand"
"k8s.io/client-go/tools/remotecommand"
"github.com/zalando-incubator/postgres-operator/pkg/spec"
)
@@ -16,8 +17,7 @@ func (c *Controller) ExecCommand(podName spec.NamespacedName, command []string)
execOut bytes.Buffer
execErr bytes.Buffer
)
pod, err := c.KubeClient.Pods(podName.Namespace).Get(podName.Name)
pod, err := c.KubeClient.Pods(podName.Namespace).Get(podName.Name, meta_v1.GetOptions{})
if err != nil {
return "", fmt.Errorf("Can't get Pod info: %s", err)
}
+7 -44
View File
@@ -1,58 +1,21 @@
package controller
import (
"k8s.io/client-go/pkg/api"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/runtime"
"k8s.io/client-go/pkg/watch"
"github.com/zalando-incubator/postgres-operator/pkg/spec"
"github.com/zalando-incubator/postgres-operator/pkg/util"
)
func (c *Controller) podListFunc(options api.ListOptions) (runtime.Object, error) {
var labelSelector string
var fieldSelector string
if options.LabelSelector != nil {
labelSelector = options.LabelSelector.String()
}
if options.FieldSelector != nil {
fieldSelector = options.FieldSelector.String()
}
opts := v1.ListOptions{
LabelSelector: labelSelector,
FieldSelector: fieldSelector,
Watch: options.Watch,
ResourceVersion: options.ResourceVersion,
TimeoutSeconds: options.TimeoutSeconds,
}
return c.KubeClient.CoreV1().Pods(c.opConfig.Namespace).List(opts)
func (c *Controller) podListFunc(options meta_v1.ListOptions) (runtime.Object, error) {
return c.KubeClient.CoreV1().Pods(c.opConfig.Namespace).List(options)
}
func (c *Controller) podWatchFunc(options api.ListOptions) (watch.Interface, error) {
var labelSelector string
var fieldSelector string
if options.LabelSelector != nil {
labelSelector = options.LabelSelector.String()
}
if options.FieldSelector != nil {
fieldSelector = options.FieldSelector.String()
}
opts := v1.ListOptions{
LabelSelector: labelSelector,
FieldSelector: fieldSelector,
Watch: options.Watch,
ResourceVersion: options.ResourceVersion,
TimeoutSeconds: options.TimeoutSeconds,
}
return c.KubeClient.CoreV1Client.Pods(c.opConfig.Namespace).Watch(opts)
func (c *Controller) podWatchFunc(options meta_v1.ListOptions) (watch.Interface, error) {
return c.KubeClient.CoreV1().Pods(c.opConfig.Namespace).Watch(options)
}
func (c *Controller) podAdd(obj interface{}) {
+8 -7
View File
@@ -4,12 +4,13 @@ import (
"fmt"
"reflect"
"k8s.io/apimachinery/pkg/api/meta"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/meta"
"k8s.io/client-go/pkg/fields"
"k8s.io/client-go/pkg/runtime"
"k8s.io/client-go/pkg/types"
"k8s.io/client-go/pkg/watch"
"k8s.io/client-go/tools/cache"
"github.com/zalando-incubator/postgres-operator/pkg/cluster"
@@ -18,7 +19,7 @@ import (
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
)
func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, error) {
func (c *Controller) clusterListFunc(options meta_v1.ListOptions) (runtime.Object, error) {
c.logger.Info("Getting list of currently running clusters")
req := c.RestClient.Get().
@@ -68,7 +69,7 @@ func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, e
return object, err
}
func (c *Controller) clusterWatchFunc(options api.ListOptions) (watch.Interface, error) {
func (c *Controller) clusterWatchFunc(options meta_v1.ListOptions) (watch.Interface, error) {
req := c.RestClient.Get().
RequestURI(fmt.Sprintf(constants.WatchClustersURITemplate, c.opConfig.Namespace)).
VersionedParams(&options, api.ParameterCodec).
+4 -3
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"hash/crc32"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/pkg/api/v1"
extv1beta "k8s.io/client-go/pkg/apis/extensions/v1beta1"
@@ -33,7 +34,7 @@ func (c *Controller) getOAuthToken() (string, error) {
// Temporary getting postgresql-operator secret from the NamespaceDefault
credentialsSecret, err := c.KubeClient.
Secrets(c.opConfig.OAuthTokenSecretName.Namespace).
Get(c.opConfig.OAuthTokenSecretName.Name)
Get(c.opConfig.OAuthTokenSecretName.Name, meta_v1.GetOptions{})
if err != nil {
c.logger.Debugf("Oauth token secret name: %s", c.opConfig.OAuthTokenSecretName)
@@ -50,7 +51,7 @@ func (c *Controller) getOAuthToken() (string, error) {
func thirdPartyResource(TPRName string) *extv1beta.ThirdPartyResource {
return &extv1beta.ThirdPartyResource{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: meta_v1.ObjectMeta{
//ThirdPartyResources are cluster-wide
Name: TPRName,
},
@@ -90,7 +91,7 @@ func (c *Controller) getInfrastructureRoles() (result map[string]spec.PgUser, er
infraRolesSecret, err := c.KubeClient.
Secrets(c.opConfig.InfrastructureRolesSecretName.Namespace).
Get(c.opConfig.InfrastructureRolesSecretName.Name)
Get(c.opConfig.InfrastructureRolesSecretName.Name, meta_v1.GetOptions{})
if err != nil {
c.logger.Debugf("Infrastructure roles secret name: %s", c.opConfig.InfrastructureRolesSecretName)
return nil, fmt.Errorf("Can't get infrastructure roles Secret: %s", err)