replace acidClientSet with acid getters in K8s client
This commit is contained in:
		
							parent
							
								
									641c2052f4
								
							
						
					
					
						commit
						37bc33d176
					
				| 
						 | 
					@ -6,15 +6,17 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/stretchr/testify/assert"
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
	acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
						acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
				
			||||||
 | 
						fakeacidv1 "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/fake"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util"
 | 
						"github.com/zalando/postgres-operator/pkg/util"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/config"
 | 
						"github.com/zalando/postgres-operator/pkg/util/config"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
						"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/client-go/kubernetes/fake"
 | 
						k8sFake "k8s.io/client-go/kubernetes/fake"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *fake.Clientset) {
 | 
					func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *k8sFake.Clientset) {
 | 
				
			||||||
	clientSet := fake.NewSimpleClientset()
 | 
						clientSet := k8sFake.NewSimpleClientset()
 | 
				
			||||||
 | 
						acidClientSet := fakeacidv1.NewSimpleClientset()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return k8sutil.KubernetesClient{
 | 
						return k8sutil.KubernetesClient{
 | 
				
			||||||
		DeploymentsGetter:            clientSet.AppsV1(),
 | 
							DeploymentsGetter:            clientSet.AppsV1(),
 | 
				
			||||||
| 
						 | 
					@ -25,6 +27,7 @@ func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *fake.Clientset) {
 | 
				
			||||||
		SecretsGetter:                clientSet.CoreV1(),
 | 
							SecretsGetter:                clientSet.CoreV1(),
 | 
				
			||||||
		ServicesGetter:               clientSet.CoreV1(),
 | 
							ServicesGetter:               clientSet.CoreV1(),
 | 
				
			||||||
		StatefulSetsGetter:           clientSet.AppsV1(),
 | 
							StatefulSetsGetter:           clientSet.AppsV1(),
 | 
				
			||||||
 | 
							PostgresqlsGetter:            acidClientSet.AcidV1(),
 | 
				
			||||||
	}, clientSet
 | 
						}, clientSet
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,12 +57,14 @@ func TestInheritedAnnotations(t *testing.T) {
 | 
				
			||||||
					ClusterLabels:        map[string]string{"application": "spilo"},
 | 
										ClusterLabels:        map[string]string{"application": "spilo"},
 | 
				
			||||||
					ClusterNameLabel:     "cluster-name",
 | 
										ClusterNameLabel:     "cluster-name",
 | 
				
			||||||
					InheritedAnnotations: []string{"owned-by"},
 | 
										InheritedAnnotations: []string{"owned-by"},
 | 
				
			||||||
 | 
										PodRoleLabel:         "spilo-role",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		}, client, pg, logger, eventRecorder)
 | 
							}, client, pg, logger, eventRecorder)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cluster.Name = clusterName
 | 
						cluster.Name = clusterName
 | 
				
			||||||
	cluster.Namespace = namespace
 | 
						cluster.Namespace = namespace
 | 
				
			||||||
 | 
						cluster.Create()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// test annotationsSet function
 | 
						// test annotationsSet function
 | 
				
			||||||
	inheritedAnnotations := cluster.annotationsSet(map[string]string{})
 | 
						inheritedAnnotations := cluster.annotationsSet(map[string]string{})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,9 @@ import (
 | 
				
			||||||
	batchv1beta1 "k8s.io/api/batch/v1beta1"
 | 
						batchv1beta1 "k8s.io/api/batch/v1beta1"
 | 
				
			||||||
	clientbatchv1beta1 "k8s.io/client-go/kubernetes/typed/batch/v1beta1"
 | 
						clientbatchv1beta1 "k8s.io/client-go/kubernetes/typed/batch/v1beta1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
						apiacidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
				
			||||||
 | 
						acidv1client "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned"
 | 
				
			||||||
 | 
						acidv1 "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/spec"
 | 
						"github.com/zalando/postgres-operator/pkg/spec"
 | 
				
			||||||
	apiappsv1 "k8s.io/api/apps/v1"
 | 
						apiappsv1 "k8s.io/api/apps/v1"
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
| 
						 | 
					@ -19,6 +21,7 @@ import (
 | 
				
			||||||
	apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
 | 
						apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
 | 
				
			||||||
	apiextv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
 | 
						apiextv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
 | 
				
			||||||
	apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
						apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/client-go/kubernetes"
 | 
						"k8s.io/client-go/kubernetes"
 | 
				
			||||||
	appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
 | 
						appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
 | 
				
			||||||
| 
						 | 
					@ -27,9 +30,6 @@ import (
 | 
				
			||||||
	rbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
 | 
						rbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
 | 
				
			||||||
	"k8s.io/client-go/rest"
 | 
						"k8s.io/client-go/rest"
 | 
				
			||||||
	"k8s.io/client-go/tools/clientcmd"
 | 
						"k8s.io/client-go/tools/clientcmd"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	acidv1client "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned"
 | 
					 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Int32ToPointer(value int32) *int32 {
 | 
					func Int32ToPointer(value int32) *int32 {
 | 
				
			||||||
| 
						 | 
					@ -55,9 +55,11 @@ type KubernetesClient struct {
 | 
				
			||||||
	policyv1beta1.PodDisruptionBudgetsGetter
 | 
						policyv1beta1.PodDisruptionBudgetsGetter
 | 
				
			||||||
	apiextv1.CustomResourceDefinitionsGetter
 | 
						apiextv1.CustomResourceDefinitionsGetter
 | 
				
			||||||
	clientbatchv1beta1.CronJobsGetter
 | 
						clientbatchv1beta1.CronJobsGetter
 | 
				
			||||||
 | 
						acidv1.OperatorConfigurationsGetter
 | 
				
			||||||
 | 
						acidv1.PostgresTeamsGetter
 | 
				
			||||||
 | 
						acidv1.PostgresqlsGetter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RESTClient      rest.Interface
 | 
						RESTClient rest.Interface
 | 
				
			||||||
	AcidV1ClientSet *acidv1client.Clientset
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type mockSecret struct {
 | 
					type mockSecret struct {
 | 
				
			||||||
| 
						 | 
					@ -154,15 +156,23 @@ func NewFromConfig(cfg *rest.Config) (KubernetesClient, error) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kubeClient.CustomResourceDefinitionsGetter = apiextClient.ApiextensionsV1()
 | 
						kubeClient.CustomResourceDefinitionsGetter = apiextClient.ApiextensionsV1()
 | 
				
			||||||
	kubeClient.AcidV1ClientSet = acidv1client.NewForConfigOrDie(cfg)
 | 
					
 | 
				
			||||||
 | 
						acidClient, err := acidv1client.NewForConfig(cfg)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return kubeClient, fmt.Errorf("could not create acid.zalan.do clientset: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kubeClient.OperatorConfigurationsGetter = acidClient.AcidV1()
 | 
				
			||||||
 | 
						kubeClient.PostgresTeamsGetter = acidClient.AcidV1()
 | 
				
			||||||
 | 
						kubeClient.PostgresqlsGetter = acidClient.AcidV1()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return kubeClient, nil
 | 
						return kubeClient, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SetPostgresCRDStatus of Postgres cluster
 | 
					// SetPostgresCRDStatus of Postgres cluster
 | 
				
			||||||
func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.NamespacedName, status string) (*acidv1.Postgresql, error) {
 | 
					func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.NamespacedName, status string) (*apiacidv1.Postgresql, error) {
 | 
				
			||||||
	var pg *acidv1.Postgresql
 | 
						var pg *apiacidv1.Postgresql
 | 
				
			||||||
	var pgStatus acidv1.PostgresStatus
 | 
						var pgStatus apiacidv1.PostgresStatus
 | 
				
			||||||
	pgStatus.PostgresClusterStatus = status
 | 
						pgStatus.PostgresClusterStatus = status
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	patch, err := json.Marshal(struct {
 | 
						patch, err := json.Marshal(struct {
 | 
				
			||||||
| 
						 | 
					@ -176,7 +186,7 @@ func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.Namespaced
 | 
				
			||||||
	// we cannot do a full scale update here without fetching the previous manifest (as the resourceVersion may differ),
 | 
						// we cannot do a full scale update here without fetching the previous manifest (as the resourceVersion may differ),
 | 
				
			||||||
	// however, we could do patch without it. In the future, once /status subresource is there (starting Kubernetes 1.11)
 | 
						// however, we could do patch without it. In the future, once /status subresource is there (starting Kubernetes 1.11)
 | 
				
			||||||
	// we should take advantage of it.
 | 
						// we should take advantage of it.
 | 
				
			||||||
	pg, err = client.AcidV1ClientSet.AcidV1().Postgresqls(clusterName.Namespace).Patch(
 | 
						pg, err = client.PostgresqlsGetter.Postgresqls(clusterName.Namespace).Patch(
 | 
				
			||||||
		context.TODO(), clusterName.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "status")
 | 
							context.TODO(), clusterName.Name, types.MergePatchType, patch, metav1.PatchOptions{}, "status")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return pg, fmt.Errorf("could not update status: %v", err)
 | 
							return pg, fmt.Errorf("could not update status: %v", err)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue