Skip to content

Commit

Permalink
Merge pull request #97 from csrwng/support_external_cp
Browse files Browse the repository at this point in the history
Support External control plane topology
  • Loading branch information
openshift-merge-robot committed Jul 23, 2021
2 parents 360fe06 + a79a33b commit 9e27d9f
Show file tree
Hide file tree
Showing 135 changed files with 11,732 additions and 11,002 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/google/go-cmp v0.5.5
github.com/google/gofuzz v1.2.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0
github.com/openshift/api v0.0.0-20210521075222-e273a339932a
github.com/openshift/build-machinery-go v0.0.0-20210423112049-9415d7ebd33e
github.com/openshift/api v0.0.0-20210719174558-55d730c80aa9
github.com/openshift/build-machinery-go v0.0.0-20210712174854-1bb7fd1518d3
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
github.com/openshift/library-go v0.0.0-20210531122633-91d29fb786be
github.com/prometheus/client_golang v1.7.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/openshift/api v0.0.0-20210521075222-e273a339932a h1:aBPwLqCg66SbQd+HrjB1GhgTfPtqSY4aeB022tEYmE0=
github.com/openshift/api v0.0.0-20210521075222-e273a339932a/go.mod h1:izBmoXbUu3z5kUa4FjZhvekTsyzIWiOoaIgJiZBBMQs=
github.com/openshift/build-machinery-go v0.0.0-20210423112049-9415d7ebd33e h1:F7rBobgSjtYL3/zsgDUjlTVx3Z06hdgpoldpDcn7jzc=
github.com/openshift/api v0.0.0-20210719174558-55d730c80aa9 h1:5XE/Uj3vJX/HUijKIlUsOhUDd6Urm6dQliIGi0GyiZE=
github.com/openshift/api v0.0.0-20210719174558-55d730c80aa9/go.mod h1:6CGz601vxLz2y2Xa51k5bnbAz0yH2oKMDH28yC2MT3w=
github.com/openshift/build-machinery-go v0.0.0-20210423112049-9415d7ebd33e/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/build-machinery-go v0.0.0-20210712174854-1bb7fd1518d3 h1:hYMLjavR8LrcCva788SxDqYjRc1k2w0LNGi7eX9vY5Y=
github.com/openshift/build-machinery-go v0.0.0-20210712174854-1bb7fd1518d3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 h1:ZHRIMCFIJN1p9LsJt4HQ+akDrys4PrYnXzOWI5LK03I=
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142/go.mod h1:fjS8r9mqDVsPb5td3NehsNOAWa4uiFkYEfVZioQ2gH0=
github.com/openshift/kubernetes-apiserver v0.0.0-20210419140141-620426e63a99 h1:KrCYRAJcgZYzMCB1PjJHJMYPu/d+dEkelq5eYyi0fDw=
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

operatorv1 "github.com/openshift/api/operator/v1"
configlisterv1 "github.com/openshift/client-go/config/listers/config/v1"
"github.com/openshift/cluster-csi-snapshot-controller-operator/pkg/operatorclient"
corev1 "k8s.io/api/core/v1"
apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand Down Expand Up @@ -59,6 +60,7 @@ type csiSnapshotOperator struct {

syncHandler func() error

infraLister configlisterv1.InfrastructureLister
nodeLister corelistersv1.NodeLister
crdLister apiextlistersv1.CustomResourceDefinitionLister
crdListerSynced cache.InformerSynced
Expand All @@ -79,6 +81,7 @@ func NewCSISnapshotControllerOperator(
crdInformer apiextinformersv1.CustomResourceDefinitionInformer,
crdClient apiextclient.Interface,
deployInformer appsinformersv1.DeploymentInformer,
infraLister configlisterv1.InfrastructureLister,
kubeClient kubernetes.Interface,
versionGetter status.VersionGetter,
eventRecorder events.Recorder,
Expand All @@ -97,6 +100,7 @@ func NewCSISnapshotControllerOperator(
operatorVersion: operatorVersion,
operandVersion: operandVersion,
csiSnapshotControllerImage: csiSnapshotControllerImage,
infraLister: infraLister,
}

nodeInformer.Informer().AddEventHandler(csiOperator.eventHandler("node"))
Expand Down
10 changes: 10 additions & 0 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"time"

"github.com/google/go-cmp/cmp"
configv1 "github.com/openshift/api/config/v1"
opv1 "github.com/openshift/api/operator/v1"
fakecfg "github.com/openshift/client-go/config/clientset/versioned/fake"
cfginformers "github.com/openshift/client-go/config/informers/externalversions"
fakeop "github.com/openshift/client-go/operator/clientset/versioned/fake"
opinformers "github.com/openshift/client-go/operator/informers/externalversions"
"github.com/openshift/cluster-csi-snapshot-controller-operator/assets"
Expand Down Expand Up @@ -48,6 +51,8 @@ type testContext struct {
extAPIInformers apiextinformers.SharedInformerFactory
operatorClient *fakeop.Clientset
operatorInformers opinformers.SharedInformerFactory
configClient *fakecfg.Clientset
configInformers cfginformers.SharedInformerFactory
}

type testObjects struct {
Expand Down Expand Up @@ -125,6 +130,10 @@ func newOperator(test operatorTest) *testContext {
if test.reactors.csiSnapshotControllers != nil {
test.reactors.csiSnapshotControllers(operatorClient, operatorInformerFactory)
}
defaultInfra := &configv1.Infrastructure{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}}
configClient := fakecfg.NewSimpleClientset(defaultInfra)
configInformerFactory := cfginformers.NewSharedInformerFactory(configClient, 0)
configInformerFactory.Config().V1().Infrastructures().Informer().GetIndexer().Add(defaultInfra)

// Add global reactors
addGenerationReactor(coreClient)
Expand All @@ -144,6 +153,7 @@ func newOperator(test operatorTest) *testContext {
extAPIInformerFactory.Apiextensions().V1().CustomResourceDefinitions(),
extAPIClient,
coreInformerFactory.Apps().V1().Deployments(),
configInformerFactory.Config().V1().Infrastructures().Lister(),
coreClient,
versionGetter,
recorder,
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
ctrlctx.APIExtInformerFactory.Apiextensions().V1().CustomResourceDefinitions(),
ctrlctx.ClientBuilder.APIExtClientOrDie(targetName),
ctrlctx.KubeNamespacedInformerFactory.Apps().V1().Deployments(),
configInformers.Config().V1().Infrastructures().Lister(),
kubeClient,
versionGetter,
controllerConfig.EventRecorder,
Expand All @@ -101,6 +102,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
ctrlctx.KubeNamespacedInformerFactory.Core().V1().Nodes(),
ctrlctx.KubeNamespacedInformerFactory.Apps().V1().Deployments(),
ctrlctx.KubeNamespacedInformerFactory.Admissionregistration().V1().ValidatingWebhookConfigurations(),
configInformers.Config().V1().Infrastructures(),
kubeClient,
controllerConfig.EventRecorder,
os.Getenv(webhookImageEnvName),
Expand Down
16 changes: 16 additions & 0 deletions pkg/operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
"github.com/openshift/library-go/pkg/operator/resource/resourceread"
"github.com/openshift/library-go/pkg/operator/v1helpers"
)

const (
infraConfigName = "cluster"
)

var crds = [...]string{"volumesnapshots.yaml",
"volumesnapshotcontents.yaml",
"volumesnapshotclasses.yaml"}
Expand Down Expand Up @@ -141,13 +146,24 @@ func (c *csiSnapshotOperator) getExpectedDeployment(instance *operatorv1.CSISnap
deployment := resourceread.ReadDeploymentV1OrDie(deploymentBytes)
deployment.Spec.Template.Spec.Containers[0].Image = c.csiSnapshotControllerImage

infra, err := c.infraLister.Get(infraConfigName)
if err != nil {
return nil, err
}

logLevel := getLogLevel(instance.Spec.LogLevel)
for i, arg := range deployment.Spec.Template.Spec.Containers[0].Args {
if strings.HasPrefix(arg, "--v=") {
deployment.Spec.Template.Spec.Containers[0].Args[i] = fmt.Sprintf("--v=%d", logLevel)
}
}

// If the topology mode is external, there are no master nodes. Update the
// node selector to remove the master node selector.
if infra.Status.ControlPlaneTopology == configv1.ExternalTopologyMode {
deployment.Spec.Template.Spec.NodeSelector = map[string]string{}
}

nodeSelector := deployment.Spec.Template.Spec.NodeSelector
nodes, err := c.nodeLister.List(labels.SelectorFromSet(nodeSelector))
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions pkg/operator/webhookdeployment/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"strconv"
"strings"

configv1 "github.com/openshift/api/config/v1"
operatorapi "github.com/openshift/api/operator/v1"
configinformerv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1"
configlisterv1 "github.com/openshift/client-go/config/listers/config/v1"
"github.com/openshift/cluster-csi-snapshot-controller-operator/assets"
"github.com/openshift/cluster-csi-snapshot-controller-operator/pkg/operatorclient"
"github.com/openshift/library-go/pkg/controller/factory"
Expand Down Expand Up @@ -34,6 +37,7 @@ type csiSnapshotWebhookController struct {
client operatorclient.OperatorClient
kubeClient kubernetes.Interface
nodeLister corelistersv1.NodeLister
infraLister configlisterv1.InfrastructureLister
eventRecorder events.Recorder

queue workqueue.RateLimitingInterface
Expand All @@ -46,6 +50,7 @@ const (
webhookVersionName = "CSISnapshotWebhookDeployment"
deploymentAsset = "webhook_deployment.yaml"
webhookAsset = "webhook_config.yaml"
infraConfigName = "cluster"
)

var (
Expand All @@ -66,6 +71,7 @@ func NewCSISnapshotWebhookController(
nodeInformer coreinformersv1.NodeInformer,
deployInformer appsinformersv1.DeploymentInformer,
webhookInformer admissionnformersv1.ValidatingWebhookConfigurationInformer,
infraInformer configinformerv1.InfrastructureInformer,
kubeClient kubernetes.Interface,
eventRecorder events.Recorder,
csiSnapshotWebhookImage string,
Expand All @@ -74,6 +80,7 @@ func NewCSISnapshotWebhookController(
client: client,
kubeClient: kubeClient,
nodeLister: nodeInformer.Lister(),
infraLister: infraInformer.Lister(),
eventRecorder: eventRecorder,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "csi-snapshot-controller"),
csiSnapshotWebhookImage: csiSnapshotWebhookImage,
Expand All @@ -84,6 +91,7 @@ func NewCSISnapshotWebhookController(
nodeInformer.Informer(),
deployInformer.Informer(),
webhookInformer.Informer(),
infraInformer.Informer(),
).ToController(WebhookControllerName, eventRecorder.WithComponentSuffix(WebhookControllerName))
}

Expand All @@ -105,6 +113,16 @@ func (c *csiSnapshotWebhookController) sync(ctx context.Context, syncCtx factory
return err
}

infra, err := c.infraLister.Get(infraConfigName)
if err != nil {
return err
}
// If the topology mode is external, there are no master nodes. Update the
// node selector to remove the master node selector.
if infra.Status.ControlPlaneTopology == configv1.ExternalTopologyMode {
deployment.Spec.Template.Spec.NodeSelector = map[string]string{}
}

// Set the number of replicas according to the number of nodes available
nodeSelector := deployment.Spec.Template.Spec.NodeSelector
nodes, err := c.nodeLister.List(labels.SelectorFromSet(nodeSelector))
Expand Down
9 changes: 9 additions & 0 deletions pkg/operator/webhookdeployment/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
configv1 "github.com/openshift/api/config/v1"
opv1 "github.com/openshift/api/operator/v1"
fakecfg "github.com/openshift/client-go/config/clientset/versioned/fake"
cfginformers "github.com/openshift/client-go/config/informers/externalversions"
fakeop "github.com/openshift/client-go/operator/clientset/versioned/fake"
opinformers "github.com/openshift/client-go/operator/informers/externalversions"
"github.com/openshift/cluster-csi-snapshot-controller-operator/assets"
Expand Down Expand Up @@ -103,6 +106,11 @@ func newOperator(test operatorTest) *testContext {
Informers: operatorInformerFactory,
}

defaultInfra := &configv1.Infrastructure{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}}
configClient := fakecfg.NewSimpleClientset(defaultInfra)
configInformerFactory := cfginformers.NewSharedInformerFactory(configClient, 0)
configInformerFactory.Config().V1().Infrastructures().Informer().GetIndexer().Add(defaultInfra)

// Add global reactors
addGenerationReactor(coreClient)

Expand All @@ -112,6 +120,7 @@ func newOperator(test operatorTest) *testContext {
coreInformerFactory.Core().V1().Nodes(),
coreInformerFactory.Apps().V1().Deployments(),
coreInformerFactory.Admissionregistration().V1().ValidatingWebhookConfigurations(),
configInformerFactory.Config().V1().Infrastructures(),
coreClient,
recorder,
test.image,
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/openshift/api/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e27d9f

Please sign in to comment.