mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-02 23:11:48 +02:00
client-go v4.0.0-beta0
go fmt glide
This commit is contained in:
@@ -11,11 +11,11 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
"k8s.io/client-go/pkg/types"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
@@ -66,7 +66,7 @@ type Cluster struct {
|
||||
mu sync.Mutex
|
||||
masterLess bool
|
||||
userSyncStrategy spec.UserSyncer
|
||||
deleteOptions *v1.DeleteOptions
|
||||
deleteOptions *meta_v1.DeleteOptions
|
||||
podEventsQueue *cache.FIFO
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func New(cfg Config, pgSpec spec.Postgresql, logger *logrus.Entry) *Cluster {
|
||||
kubeResources: kubeResources,
|
||||
masterLess: false,
|
||||
userSyncStrategy: users.DefaultUserSyncStrategy{},
|
||||
deleteOptions: &v1.DeleteOptions{OrphanDependents: &orphanDependents},
|
||||
deleteOptions: &meta_v1.DeleteOptions{OrphanDependents: &orphanDependents},
|
||||
podEventsQueue: podEventsQueue,
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (c *Cluster) setStatus(status spec.PostgresStatus) {
|
||||
}
|
||||
request := []byte(fmt.Sprintf(`{"status": %s}`, string(b))) //TODO: Look into/wait for k8s go client methods
|
||||
|
||||
_, err = c.RestClient.Patch(api.MergePatchType).
|
||||
_, err = c.RestClient.Patch(types.MergePatchType).
|
||||
RequestURI(c.Metadata.GetSelfLink()).
|
||||
Body(request).
|
||||
DoRaw()
|
||||
|
||||
+3
-2
@@ -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"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (
|
||||
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("could not get pod info: %v", err)
|
||||
}
|
||||
|
||||
+10
-9
@@ -1,14 +1,15 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"encoding/json"
|
||||
"k8s.io/client-go/pkg/api/resource"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
"k8s.io/client-go/pkg/util/intstr"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
||||
@@ -311,7 +312,7 @@ func (c *Cluster) generatePodTemplate(resourceRequirements *v1.ResourceRequireme
|
||||
}
|
||||
|
||||
template := v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Labels: c.labelsSet(),
|
||||
Namespace: c.Metadata.Name,
|
||||
},
|
||||
@@ -337,7 +338,7 @@ func (c *Cluster) generateStatefulSet(spec spec.PostgresSpec) (*v1beta1.Stateful
|
||||
}
|
||||
|
||||
statefulSet := &v1beta1.StatefulSet{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: c.Metadata.Name,
|
||||
Namespace: c.Metadata.Namespace,
|
||||
Labels: c.labelsSet(),
|
||||
@@ -354,7 +355,7 @@ func (c *Cluster) generateStatefulSet(spec spec.PostgresSpec) (*v1beta1.Stateful
|
||||
}
|
||||
|
||||
func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string) (*v1.PersistentVolumeClaim, error) {
|
||||
metadata := v1.ObjectMeta{
|
||||
metadata := meta_v1.ObjectMeta{
|
||||
Name: constants.DataVolumeName,
|
||||
}
|
||||
if volumeStorageClass != "" {
|
||||
@@ -412,7 +413,7 @@ func (c *Cluster) generateSingleUserSecret(namespace string, pgUser spec.PgUser)
|
||||
}
|
||||
username := pgUser.Name
|
||||
secret := v1.Secret{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: c.credentialSecretName(username),
|
||||
Namespace: namespace,
|
||||
Labels: c.labelsSet(),
|
||||
@@ -468,7 +469,7 @@ func (c *Cluster) generateService(role PostgresRole, newSpec *spec.PostgresSpec)
|
||||
}
|
||||
|
||||
service := &v1.Service{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: c.Metadata.Namespace,
|
||||
Labels: c.roleLabelsSet(role),
|
||||
@@ -482,7 +483,7 @@ func (c *Cluster) generateService(role PostgresRole, newSpec *spec.PostgresSpec)
|
||||
|
||||
func (c *Cluster) generateMasterEndpoints(subsets []v1.EndpointSubset) *v1.Endpoints {
|
||||
endpoints := &v1.Endpoints{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: c.Metadata.Name,
|
||||
Namespace: c.Metadata.Namespace,
|
||||
Labels: c.roleLabelsSet(Master),
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ package cluster
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
|
||||
func (c *Cluster) listPods() ([]v1.Pod, error) {
|
||||
ns := c.Metadata.Namespace
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: c.labelsSet().String(),
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ func (c *Cluster) recreatePods() error {
|
||||
ls := c.labelsSet()
|
||||
namespace := c.Metadata.Namespace
|
||||
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: ls.String(),
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ package cluster
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/client-go/pkg/api"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
|
||||
func (c *Cluster) loadResources() error {
|
||||
ns := c.Metadata.Namespace
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: c.labelsSet().String(),
|
||||
}
|
||||
|
||||
@@ -148,7 +149,7 @@ func (c *Cluster) updateStatefulSet(newStatefulSet *v1beta1.StatefulSet) error {
|
||||
|
||||
statefulSet, err := c.KubeClient.StatefulSets(c.Statefulset.Namespace).Patch(
|
||||
c.Statefulset.Name,
|
||||
api.MergePatchType,
|
||||
types.MergePatchType,
|
||||
patchData, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not patch statefulset '%s': %v", statefulSetName, err)
|
||||
@@ -171,7 +172,7 @@ func (c *Cluster) replaceStatefulSet(newStatefulSet *v1beta1.StatefulSet) error
|
||||
orphanDepencies := true
|
||||
oldStatefulset := c.Statefulset
|
||||
|
||||
options := v1.DeleteOptions{OrphanDependents: &orphanDepencies}
|
||||
options := meta_v1.DeleteOptions{OrphanDependents: &orphanDepencies}
|
||||
if err := c.KubeClient.StatefulSets(oldStatefulset.Namespace).Delete(oldStatefulset.Name, &options); err != nil {
|
||||
return fmt.Errorf("could not delete statefulset '%s': %v", statefulSetName, err)
|
||||
}
|
||||
@@ -182,7 +183,7 @@ func (c *Cluster) replaceStatefulSet(newStatefulSet *v1beta1.StatefulSet) error
|
||||
|
||||
err := retryutil.Retry(constants.StatefulsetDeletionInterval, constants.StatefulsetDeletionTimeout,
|
||||
func() (bool, error) {
|
||||
_, err := c.KubeClient.StatefulSets(oldStatefulset.Namespace).Get(oldStatefulset.Name)
|
||||
_, err := c.KubeClient.StatefulSets(oldStatefulset.Namespace).Get(oldStatefulset.Name, meta_v1.GetOptions{})
|
||||
|
||||
return err != nil, nil
|
||||
})
|
||||
@@ -262,7 +263,7 @@ func (c *Cluster) updateService(role PostgresRole, newService *v1.Service) error
|
||||
if role == Master {
|
||||
// for the master service we need to re-create the endpoint as well. Get the up-to-date version of
|
||||
// the addresses stored in it before the service is deleted (deletion of the service removes the endpooint)
|
||||
currentEndpoint, err = c.KubeClient.Endpoints(c.Service[role].Namespace).Get(c.Service[role].Name)
|
||||
currentEndpoint, err = c.KubeClient.Endpoints(c.Service[role].Namespace).Get(c.Service[role].Name, meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get current cluster endpoints: %v", err)
|
||||
}
|
||||
@@ -294,7 +295,7 @@ func (c *Cluster) updateService(role PostgresRole, newService *v1.Service) error
|
||||
|
||||
_, err := c.KubeClient.Services(c.Service[role].Namespace).Patch(
|
||||
c.Service[role].Name,
|
||||
api.StrategicMergePatchType,
|
||||
types.StrategicMergePatchType,
|
||||
[]byte(annotationsPatchData), "")
|
||||
|
||||
if err != nil {
|
||||
@@ -309,7 +310,7 @@ func (c *Cluster) updateService(role PostgresRole, newService *v1.Service) error
|
||||
|
||||
svc, err := c.KubeClient.Services(c.Service[role].Namespace).Patch(
|
||||
c.Service[role].Name,
|
||||
api.MergePatchType,
|
||||
types.MergePatchType,
|
||||
patchData, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not patch service '%s': %v", serviceName, err)
|
||||
@@ -371,7 +372,7 @@ func (c *Cluster) applySecrets() error {
|
||||
secret, err := c.KubeClient.Secrets(secretSpec.Namespace).Create(secretSpec)
|
||||
if k8sutil.ResourceAlreadyExists(err) {
|
||||
var userMap map[string]spec.PgUser
|
||||
curSecret, err := c.KubeClient.Secrets(secretSpec.Namespace).Get(secretSpec.Name)
|
||||
curSecret, err := c.KubeClient.Secrets(secretSpec.Namespace).Get(secretSpec.Name, meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get current secret: %v", err)
|
||||
}
|
||||
|
||||
+7
-6
@@ -6,9 +6,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
"k8s.io/client-go/pkg/labels"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util"
|
||||
@@ -123,7 +124,7 @@ func (c *Cluster) 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)
|
||||
@@ -193,7 +194,7 @@ func (c *Cluster) waitForPodDeletion(podEvents chan spec.PodEvent) error {
|
||||
func (c *Cluster) waitStatefulsetReady() error {
|
||||
return retryutil.Retry(c.OpConfig.ResourceCheckInterval, c.OpConfig.ResourceCheckTimeout,
|
||||
func() (bool, error) {
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: c.labelsSet().String(),
|
||||
}
|
||||
ss, err := c.KubeClient.StatefulSets(c.Metadata.Namespace).List(listOptions)
|
||||
@@ -213,15 +214,15 @@ func (c *Cluster) waitPodLabelsReady() error {
|
||||
ls := c.labelsSet()
|
||||
namespace := c.Metadata.Namespace
|
||||
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: ls.String(),
|
||||
}
|
||||
masterListOption := v1.ListOptions{
|
||||
masterListOption := meta_v1.ListOptions{
|
||||
LabelSelector: labels.Merge(ls, labels.Set{
|
||||
c.OpConfig.PodRoleLabel: constants.PodRoleMaster,
|
||||
}).String(),
|
||||
}
|
||||
replicaListOption := v1.ListOptions{
|
||||
replicaListOption := meta_v1.ListOptions{
|
||||
LabelSelector: labels.Merge(ls, labels.Set{
|
||||
c.OpConfig.PodRoleLabel: constants.PodRoleReplica,
|
||||
}).String(),
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"k8s.io/client-go/pkg/api/resource"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
|
||||
func (c *Cluster) listPersistentVolumeClaims() ([]v1.PersistentVolumeClaim, error) {
|
||||
ns := c.Metadata.Namespace
|
||||
listOptions := v1.ListOptions{
|
||||
listOptions := meta_v1.ListOptions{
|
||||
LabelSelector: c.labelsSet().String(),
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ func (c *Cluster) listPersistentVolumes() ([]*v1.PersistentVolume, error) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
pv, err := c.KubeClient.PersistentVolumes().Get(pvc.Spec.VolumeName)
|
||||
pv, err := c.KubeClient.PersistentVolumes().Get(pvc.Spec.VolumeName, meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get PersistentVolume: %v", err)
|
||||
}
|
||||
|
||||
@@ -99,13 +99,11 @@ func (c *Controller) initController() {
|
||||
constants.QueueResyncPeriodTPR,
|
||||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
|
||||
if err := c.postgresqlInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
c.postgresqlInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: c.postgresqlAdd,
|
||||
UpdateFunc: c.postgresqlUpdate,
|
||||
DeleteFunc: c.postgresqlDelete,
|
||||
}); err != nil {
|
||||
c.logger.Fatalf("could not add event handlers: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// Pods
|
||||
podLw := &cache.ListWatch{
|
||||
@@ -119,13 +117,11 @@ func (c *Controller) initController() {
|
||||
constants.QueueResyncPeriodPod,
|
||||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
|
||||
if err := c.podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
c.podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: c.podAdd,
|
||||
UpdateFunc: c.podUpdate,
|
||||
DeleteFunc: c.podDelete,
|
||||
}); err != nil {
|
||||
c.logger.Fatalf("could not add event handlers: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
c.clusterEventQueues = make([]*cache.FIFO, c.opConfig.Workers)
|
||||
for i := range c.clusterEventQueues {
|
||||
|
||||
+7
-22
@@ -1,27 +1,20 @@
|
||||
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) {
|
||||
func (c *Controller) podListFunc(options meta_v1.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{
|
||||
opts := meta_v1.ListOptions{
|
||||
LabelSelector: labelSelector,
|
||||
FieldSelector: fieldSelector,
|
||||
Watch: options.Watch,
|
||||
@@ -32,19 +25,11 @@ func (c *Controller) podListFunc(options api.ListOptions) (runtime.Object, error
|
||||
return c.KubeClient.CoreV1().Pods(c.opConfig.Namespace).List(opts)
|
||||
}
|
||||
|
||||
func (c *Controller) podWatchFunc(options api.ListOptions) (watch.Interface, error) {
|
||||
func (c *Controller) podWatchFunc(options meta_v1.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{
|
||||
opts := meta_v1.ListOptions{
|
||||
LabelSelector: labelSelector,
|
||||
FieldSelector: fieldSelector,
|
||||
Watch: options.Watch,
|
||||
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
@@ -26,14 +27,14 @@ func (c *Controller) clusterResync(stopCh <-chan struct{}) {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
c.clusterListFunc(api.ListOptions{ResourceVersion: "0"})
|
||||
c.clusterListFunc(meta_v1.ListOptions{ResourceVersion: "0"})
|
||||
case <-stopCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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().
|
||||
@@ -88,7 +89,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,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"
|
||||
|
||||
@@ -32,7 +33,7 @@ func (c *Controller) makeClusterConfig() cluster.Config {
|
||||
|
||||
func thirdPartyResource(TPRName string) *extv1beta.ThirdPartyResource {
|
||||
return &extv1beta.ThirdPartyResource{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
//ThirdPartyResources are cluster-wide
|
||||
Name: TPRName,
|
||||
},
|
||||
@@ -72,7 +73,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("could not get infrastructure roles secret: %v", err)
|
||||
|
||||
+13
-10
@@ -6,9 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/pkg/api/meta"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// MaintenanceWindow describes the time window when the operator is allowed to do maintenance on a cluster.
|
||||
@@ -71,8 +70,8 @@ const (
|
||||
|
||||
// Postgresql defines PostgreSQL Third Party (resource) Object.
|
||||
type Postgresql struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
Metadata v1.ObjectMeta `json:"metadata"`
|
||||
meta_v1.TypeMeta `json:",inline"`
|
||||
Metadata meta_v1.ObjectMeta `json:"metadata"`
|
||||
|
||||
Spec PostgresSpec `json:"spec"`
|
||||
Status PostgresStatus `json:"status,omitempty"`
|
||||
@@ -99,8 +98,8 @@ type PostgresSpec struct {
|
||||
|
||||
// PostgresqlList defines a list of PostgreSQL clusters.
|
||||
type PostgresqlList struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
Metadata unversioned.ListMeta `json:"metadata"`
|
||||
meta_v1.TypeMeta `json:",inline"`
|
||||
Metadata meta_v1.ListMeta `json:"metadata"`
|
||||
|
||||
Items []Postgresql `json:"items"`
|
||||
}
|
||||
@@ -192,17 +191,21 @@ func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
// GetObject implements Object interface for PostgreSQL TPR spec object.
|
||||
func (p *Postgresql) GetObjectKind() unversioned.ObjectKind {
|
||||
func (p *Postgresql) GetObjectKind() schema.ObjectKind {
|
||||
return &p.TypeMeta
|
||||
}
|
||||
|
||||
// GetObjectMeta implements ObjectMetaAccessor interface for PostgreSQL TPR spec object.
|
||||
func (p *Postgresql) GetObjectMeta() meta.Object {
|
||||
func (p *Postgresql) GetObjectMeta() meta_v1.Object {
|
||||
return &p.Metadata
|
||||
}
|
||||
|
||||
func (pl *PostgresqlList) GetObjectKind() schema.ObjectKind {
|
||||
return &pl.TypeMeta
|
||||
}
|
||||
|
||||
// GetListMeta implements ListMetaAccessor interface for PostgreSQL TPR List spec object.
|
||||
func (pl *PostgresqlList) GetListMeta() unversioned.List {
|
||||
func (pl *PostgresqlList) GetListMeta() meta_v1.List {
|
||||
return &pl.Metadata
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -8,8 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
var parseTimeTests = []struct {
|
||||
@@ -104,11 +104,11 @@ var unmarshalCluster = []struct {
|
||||
"kind": "Postgresql","apiVersion": "acid.zalan.do/v1",
|
||||
"metadata": {"name": "acid-testcluster1"}, "spec": {"teamId": 100}}`),
|
||||
Postgresql{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
TypeMeta: meta_v1.TypeMeta{
|
||||
Kind: "Postgresql",
|
||||
APIVersion: "acid.zalan.do/v1",
|
||||
},
|
||||
Metadata: v1.ObjectMeta{
|
||||
Metadata: meta_v1.ObjectMeta{
|
||||
Name: "acid-testcluster1",
|
||||
},
|
||||
Status: ClusterStatusInvalid,
|
||||
@@ -184,11 +184,11 @@ var unmarshalCluster = []struct {
|
||||
}
|
||||
}`),
|
||||
Postgresql{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
TypeMeta: meta_v1.TypeMeta{
|
||||
Kind: "Postgresql",
|
||||
APIVersion: "acid.zalan.do/v1",
|
||||
},
|
||||
Metadata: v1.ObjectMeta{
|
||||
Metadata: meta_v1.ObjectMeta{
|
||||
Name: "acid-testcluster1",
|
||||
},
|
||||
Spec: PostgresSpec{
|
||||
@@ -250,11 +250,11 @@ var unmarshalCluster = []struct {
|
||||
{
|
||||
[]byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "teapot-testcluster1"}, "spec": {"teamId": "acid"}}`),
|
||||
Postgresql{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
TypeMeta: meta_v1.TypeMeta{
|
||||
Kind: "Postgresql",
|
||||
APIVersion: "acid.zalan.do/v1",
|
||||
},
|
||||
Metadata: v1.ObjectMeta{
|
||||
Metadata: meta_v1.ObjectMeta{
|
||||
Name: "teapot-testcluster1",
|
||||
},
|
||||
Spec: PostgresSpec{TeamID: "acid"},
|
||||
@@ -278,16 +278,16 @@ var postgresqlList = []struct {
|
||||
}{
|
||||
{[]byte(`{"apiVersion":"v1","items":[{"apiVersion":"acid.zalan.do/v1","kind":"Postgresql","metadata":{"labels":{"team":"acid"},"name":"acid-testcluster42","namespace":"default","resourceVersion":"30446957","selfLink":"/apis/acid.zalan.do/v1/namespaces/default/postgresqls/acid-testcluster42","uid":"857cd208-33dc-11e7-b20a-0699041e4b03"},"spec":{"allowedSourceRanges":["185.85.220.0/22"],"numberOfInstances":1,"postgresql":{"version":"9.6"},"teamId":"acid","volume":{"size":"10Gi"}},"status":"Running"}],"kind":"List","metadata":{},"resourceVersion":"","selfLink":""}`),
|
||||
PostgresqlList{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
TypeMeta: meta_v1.TypeMeta{
|
||||
Kind: "List",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
Items: []Postgresql{{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
TypeMeta: meta_v1.TypeMeta{
|
||||
Kind: "Postgresql",
|
||||
APIVersion: "acid.zalan.do/v1",
|
||||
},
|
||||
Metadata: v1.ObjectMeta{
|
||||
Metadata: meta_v1.ObjectMeta{
|
||||
Name: "acid-testcluster42",
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"team": "acid"},
|
||||
|
||||
+1
-1
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"database/sql"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/types"
|
||||
)
|
||||
|
||||
// EvenType contains type of the events for the TPRs and Pods received from Kubernetes
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
apierrors "k8s.io/client-go/pkg/api/errors"
|
||||
"k8s.io/client-go/pkg/api/unversioned"
|
||||
"k8s.io/client-go/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/runtime/serializer"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
@@ -38,21 +39,21 @@ func ResourceNotFound(err error) bool {
|
||||
}
|
||||
|
||||
func KubernetesRestClient(c *rest.Config) (*rest.RESTClient, error) {
|
||||
c.GroupVersion = &unversioned.GroupVersion{Version: constants.K8sVersion}
|
||||
c.GroupVersion = &schema.GroupVersion{Version: constants.K8sVersion}
|
||||
c.APIPath = constants.K8sAPIPath
|
||||
c.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||
|
||||
schemeBuilder := runtime.NewSchemeBuilder(
|
||||
func(scheme *runtime.Scheme) error {
|
||||
scheme.AddKnownTypes(
|
||||
unversioned.GroupVersion{
|
||||
schema.GroupVersion{
|
||||
Group: constants.TPRVendor,
|
||||
Version: constants.TPRApiVersion,
|
||||
},
|
||||
&spec.Postgresql{},
|
||||
&spec.PostgresqlList{},
|
||||
&api.ListOptions{},
|
||||
&api.DeleteOptions{},
|
||||
&meta_v1.ListOptions{},
|
||||
&meta_v1.DeleteOptions{},
|
||||
)
|
||||
return nil
|
||||
})
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/motomux/pretty"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
)
|
||||
@@ -34,7 +34,7 @@ func RandomPassword(n int) string {
|
||||
}
|
||||
|
||||
// NameFromMeta converts a metadata object to the NamespacedName name representation.
|
||||
func NameFromMeta(meta v1.ObjectMeta) spec.NamespacedName {
|
||||
func NameFromMeta(meta meta_v1.ObjectMeta) spec.NamespacedName {
|
||||
return spec.NamespacedName{
|
||||
Namespace: meta.Namespace,
|
||||
Name: meta.Name,
|
||||
|
||||
Reference in New Issue
Block a user