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"
 | 
			
		||||
	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/config"
 | 
			
		||||
	"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
			
		||||
	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) {
 | 
			
		||||
	clientSet := fake.NewSimpleClientset()
 | 
			
		||||
func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *k8sFake.Clientset) {
 | 
			
		||||
	clientSet := k8sFake.NewSimpleClientset()
 | 
			
		||||
	acidClientSet := fakeacidv1.NewSimpleClientset()
 | 
			
		||||
 | 
			
		||||
	return k8sutil.KubernetesClient{
 | 
			
		||||
		DeploymentsGetter:            clientSet.AppsV1(),
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +27,7 @@ func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *fake.Clientset) {
 | 
			
		|||
		SecretsGetter:                clientSet.CoreV1(),
 | 
			
		||||
		ServicesGetter:               clientSet.CoreV1(),
 | 
			
		||||
		StatefulSetsGetter:           clientSet.AppsV1(),
 | 
			
		||||
		PostgresqlsGetter:            acidClientSet.AcidV1(),
 | 
			
		||||
	}, clientSet
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -54,12 +57,14 @@ func TestInheritedAnnotations(t *testing.T) {
 | 
			
		|||
					ClusterLabels:        map[string]string{"application": "spilo"},
 | 
			
		||||
					ClusterNameLabel:     "cluster-name",
 | 
			
		||||
					InheritedAnnotations: []string{"owned-by"},
 | 
			
		||||
					PodRoleLabel:         "spilo-role",
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		}, client, pg, logger, eventRecorder)
 | 
			
		||||
 | 
			
		||||
	cluster.Name = clusterName
 | 
			
		||||
	cluster.Namespace = namespace
 | 
			
		||||
	cluster.Create()
 | 
			
		||||
 | 
			
		||||
	// test annotationsSet function
 | 
			
		||||
	inheritedAnnotations := cluster.annotationsSet(map[string]string{})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,9 @@ import (
 | 
			
		|||
	batchv1beta1 "k8s.io/api/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"
 | 
			
		||||
	apiappsv1 "k8s.io/api/apps/v1"
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
| 
						 | 
				
			
			@ -19,6 +21,7 @@ import (
 | 
			
		|||
	apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
 | 
			
		||||
	apiextv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
 | 
			
		||||
	apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/types"
 | 
			
		||||
	"k8s.io/client-go/kubernetes"
 | 
			
		||||
	appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
 | 
			
		||||
| 
						 | 
				
			
			@ -27,9 +30,6 @@ import (
 | 
			
		|||
	rbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
 | 
			
		||||
	"k8s.io/client-go/rest"
 | 
			
		||||
	"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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -55,9 +55,11 @@ type KubernetesClient struct {
 | 
			
		|||
	policyv1beta1.PodDisruptionBudgetsGetter
 | 
			
		||||
	apiextv1.CustomResourceDefinitionsGetter
 | 
			
		||||
	clientbatchv1beta1.CronJobsGetter
 | 
			
		||||
	acidv1.OperatorConfigurationsGetter
 | 
			
		||||
	acidv1.PostgresTeamsGetter
 | 
			
		||||
	acidv1.PostgresqlsGetter
 | 
			
		||||
 | 
			
		||||
	RESTClient      rest.Interface
 | 
			
		||||
	AcidV1ClientSet *acidv1client.Clientset
 | 
			
		||||
	RESTClient rest.Interface
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type mockSecret struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -154,15 +156,23 @@ func NewFromConfig(cfg *rest.Config) (KubernetesClient, error) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetPostgresCRDStatus of Postgres cluster
 | 
			
		||||
func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.NamespacedName, status string) (*acidv1.Postgresql, error) {
 | 
			
		||||
	var pg *acidv1.Postgresql
 | 
			
		||||
	var pgStatus acidv1.PostgresStatus
 | 
			
		||||
func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.NamespacedName, status string) (*apiacidv1.Postgresql, error) {
 | 
			
		||||
	var pg *apiacidv1.Postgresql
 | 
			
		||||
	var pgStatus apiacidv1.PostgresStatus
 | 
			
		||||
	pgStatus.PostgresClusterStatus = status
 | 
			
		||||
 | 
			
		||||
	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),
 | 
			
		||||
	// 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.
 | 
			
		||||
	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")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return pg, fmt.Errorf("could not update status: %v", err)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue