Skip to content

Commit

Permalink
Merge pull request #287 from vikaschoudhary16/deployment-client
Browse files Browse the repository at this point in the history
Use deployment client
  • Loading branch information
openshift-merge-robot authored Apr 23, 2019
2 parents 0a74be7 + 866039a commit e94611f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
fakeconfigclientset "github.com/openshift/client-go/config/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"

Expand Down Expand Up @@ -148,17 +149,21 @@ const (

func initOperator(featureGate *v1.FeatureGate, kubeclientSet *fakekube.Clientset) (*Operator, error) {
configClient := fakeos.NewSimpleClientset(featureGate)
configSharedInformer := configinformersv1.NewSharedInformerFactoryWithOptions(configClient, 10*time.Minute)
kubeNamespacedSharedInformer := informers.NewSharedInformerFactoryWithOptions(kubeclientSet, 2*time.Minute, informers.WithNamespace(targetNamespace))
configSharedInformer := configinformersv1.NewSharedInformerFactoryWithOptions(configClient, 2*time.Minute)
featureGateInformer := configSharedInformer.Config().V1().FeatureGates()
deployInformer := kubeNamespacedSharedInformer.Apps().V1().Deployments()

op := &Operator{
kubeClient: kubeclientSet,
featureGateLister: featureGateInformer.Lister(),
deployLister: deployInformer.Lister(),
ownedManifestsDir: "../../owned-manifests",
}

stop := make(<-chan struct{})
configSharedInformer.Start(stop)
kubeNamespacedSharedInformer.Start(stop)

if !cache.WaitForCacheSync(stop, featureGateInformer.Informer().HasSynced) {
return nil, fmt.Errorf("unable to wait for cache to sync")
Expand Down Expand Up @@ -246,7 +251,7 @@ func TestOperatorSyncClusterAPIControllerHealthCheckControllerDeployed(t *testin
t.Errorf("Failed to sync machine API controller: %v", err)
}

d, err := kubeclientSet.AppsV1().Deployments(targetNamespace).Get(deploymentName, metav1.GetOptions{})
d, err := op.deployLister.Deployments(targetNamespace).Get(deploymentName)
if err != nil {
t.Errorf("Failed to get %q deployment: %v", deploymentName, err)
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
"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/util/wait"

"path/filepath"
Expand Down Expand Up @@ -91,10 +90,7 @@ func (optr *Operator) syncClusterAPIController(config OperatorConfig) error {

func (optr *Operator) waitForDeploymentRollout(resource *appsv1.Deployment) error {
return wait.Poll(deploymentRolloutPollInterval, deploymentRolloutTimeout, func() (bool, error) {
// TODO(vikas): When using deployLister, an issue is happening related to the apiVersion of cluster-api objects.
// This will be debugged later on to find out the root cause. For now, working aound is to use kubeClient.AppsV1
// d, err := optr.deployLister.Deployments(resource.Namespace).Get(resource.Name)
d, err := optr.kubeClient.AppsV1().Deployments(resource.Namespace).Get(resource.Name, metav1.GetOptions{})
d, err := optr.deployLister.Deployments(resource.Namespace).Get(resource.Name)
if apierrors.IsNotFound(err) {
return false, nil
}
Expand Down

0 comments on commit e94611f

Please sign in to comment.