Skip to content

Commit

Permalink
Merge pull request #268 from ingvagabund/do-not-use-expected-policy-c…
Browse files Browse the repository at this point in the history
…m-name-in-tests

Drop code that expects the config map in openshift-config namespace to have policy-configmap name
  • Loading branch information
openshift-merge-robot committed Jul 31, 2020
2 parents 2f78288 + 6da5603 commit f6ee0ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
14 changes: 0 additions & 14 deletions pkg/operator/resourcesynccontroller/resourcesynccontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package resourcesynccontroller

import (
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

configinformers "github.com/openshift/client-go/config/informers/externalversions"
"github.com/openshift/cluster-kube-scheduler-operator/pkg/operator/operatorclient"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
Expand All @@ -14,7 +12,6 @@ import (
func NewResourceSyncController(
operatorConfigClient v1helpers.OperatorClient,
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
configInformer configinformers.SharedInformerFactory,
kubeClient kubernetes.Interface,
eventRecorder events.Recorder) (*resourcesynccontroller.ResourceSyncController, error) {

Expand All @@ -26,17 +23,6 @@ func NewResourceSyncController(
eventRecorder,
)

scheduler, err := configInformer.Config().V1().Schedulers().Lister().Get("cluster")
if err != nil {
klog.Infof("Error while listing scheduler %v", err)
}
if scheduler != nil && len(scheduler.Spec.Policy.Name) > 0 {
if err := resourceSyncController.SyncConfigMap(
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.TargetNamespace, Name: scheduler.Spec.Policy.Name},
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.GlobalUserSpecifiedConfigNamespace, Name: "policy-configmap"}); err != nil {
return nil, err
}
}
if err := resourceSyncController.SyncSecret(
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.TargetNamespace, Name: "kube-scheduler-client-cert-key"},
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.GlobalMachineSpecifiedConfigNamespace, Name: "kube-scheduler-client-cert-key"},
Expand Down
1 change: 0 additions & 1 deletion pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func RunOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
resourceSyncController, err := resourcesynccontroller.NewResourceSyncController(
operatorClient,
kubeInformersForNamespaces,
configInformers,
kubeClient,
cc.EventRecorder,
)
Expand Down
16 changes: 10 additions & 6 deletions test/e2e/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"reflect"
"strings"
"testing"
"time"
Expand All @@ -26,7 +27,10 @@ import (
k8sclient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"reflect"
)

const (
customPolicyCMName = "custom-policy-configmap"
)

func getKubeClient() (*k8sclient.Clientset, error) {
Expand Down Expand Up @@ -112,7 +116,7 @@ func createSchedulerConfigMap(ctx context.Context, kclient *k8sclient.Clientset)
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "policy-configmap",
Name: customPolicyCMName,
},
Data: map[string]string{
"policy.cfg": "{\n\"kind\" : \"Policy\",\n\"apiVersion\" : \"v1\",\n\"predicates\" : [\n\t{\"name\" : \"PodFitsHostPorts\"},\n\t{\"name\" : \"PodFitsResources\"},\n\t{\"name\": \"NoDiskConflict\"},\n\t{\"name\" : \"NoVolumeZoneConflict\"},\n\t{\"name\": \"MatchNodeSelector\"},\n\t{\"name\" : \"HostName\"}\n\t],\n\"priorities\" : [\n\t{\"name\" : \"LeastRequestedPriority\", \"weight\" : 1},\n\t{\"name\" : \"BalancedResourceAllocation\", \"weight\" : 1},\n\t{\"name\" : \"ServiceSpreadingPriority\", \"weight\" : 5},\n\t{\"name\" : \"EqualPriority\", \"weight\" : 1}\n\t]\n}\n",
Expand Down Expand Up @@ -173,7 +177,7 @@ func TestConfigMapCreation(t *testing.T) {

}
// Update scheduler CR to the name of the config map we just created.
schedulerCR.Spec.Policy.Name = "policy-configmap"
schedulerCR.Spec.Policy.Name = customPolicyCMName
if _, err = configClient.ConfigV1().Schedulers().Update(ctx, schedulerCR, metav1.UpdateOptions{}); err != nil {
t.Fatalf("Error while updating scheduler CR with error %v", err)
}
Expand All @@ -194,7 +198,7 @@ func TestConfigMapCreation(t *testing.T) {
}

// Delete the config map that was created
err = kclient.CoreV1().ConfigMaps("openshift-config").Delete(ctx, "policy-configmap", metav1.DeleteOptions{})
err = kclient.CoreV1().ConfigMaps("openshift-config").Delete(ctx, customPolicyCMName, metav1.DeleteOptions{})
if err != nil {
t.Fatalf("error waiting for config map to exist: %v\n", err)
}
Expand Down Expand Up @@ -225,7 +229,7 @@ func TestPolicyConfigMapUpdate(t *testing.T) {
}

// Update scheduler CR to the name of the config map we just created.
schedulerCR.Spec.Policy.Name = "policy-configmap"
schedulerCR.Spec.Policy.Name = customPolicyCMName
if _, err = configClient.ConfigV1().Schedulers().Update(ctx, schedulerCR, metav1.UpdateOptions{}); err != nil {
t.Fatalf("Error while updating scheduler CR with error %v", err)
}
Expand Down Expand Up @@ -266,7 +270,7 @@ func TestPolicyConfigMapUpdate(t *testing.T) {
}

// Delete the config map that was created
err = kclient.CoreV1().ConfigMaps("openshift-config").Delete(ctx, "policy-configmap", metav1.DeleteOptions{})
err = kclient.CoreV1().ConfigMaps("openshift-config").Delete(ctx, customPolicyCMName, metav1.DeleteOptions{})
if err != nil {
t.Fatalf("error waiting for config map to exist: %v\n", err)
}
Expand Down

0 comments on commit f6ee0ad

Please sign in to comment.