Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectivitycheckcontroller: use generic controller #380

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/gonum/graph v0.0.0-20170401004347-50b27dea7ebb
github.com/imdario/mergo v0.3.7
github.com/kubernetes-sigs/kube-storage-version-migrator v0.0.0-20191127225502-51849bc15f17
github.com/openshift/api v0.0.0-20200723134351-89de68875e7c
github.com/openshift/build-machinery-go v0.0.0-20200713135615-1f43d26dccc7
github.com/openshift/client-go v0.0.0-20200722173614-5a1b0aaeff15
github.com/openshift/library-go v0.0.0-20200731053141-ff55255233e3
github.com/openshift/library-go v0.0.0-20200807122248-f5cb4d19a4fe
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/openshift/client-go v0.0.0-20200722173614-5a1b0aaeff15 h1:b2QkHrmaYtY
github.com/openshift/client-go v0.0.0-20200722173614-5a1b0aaeff15/go.mod h1:yd4Zpcdk+8JyMWi6v+h78jPqK0FvXbJY41Wq3SZxl+c=
github.com/openshift/kubernetes-kube-storage-version-migrator v0.0.3-0.20200312103335-32e07ea4f8ca h1:YNtyJnE53QuEUSjl7L1AARocI021o7cU2bvh4prDtiE=
github.com/openshift/kubernetes-kube-storage-version-migrator v0.0.3-0.20200312103335-32e07ea4f8ca/go.mod h1:unEnEWccGeVxaXSRsWTjRsNxMqYXmuQjzjcPFQ91H9M=
github.com/openshift/library-go v0.0.0-20200731053141-ff55255233e3 h1:CVXMm0ycbY+y61Xsb7seCkiXd1Pj/lF4eNqpPocT7Q0=
github.com/openshift/library-go v0.0.0-20200731053141-ff55255233e3/go.mod h1:q7ebJwBFgDx4nP5jGhd+K9XgOIpKaNVh4RWpKmW61Gg=
github.com/openshift/library-go v0.0.0-20200807122248-f5cb4d19a4fe h1:Dt46qJIjHr4a0R1hEIZegKr1j9mT3E0Sfz4Y+uZ+EGc=
github.com/openshift/library-go v0.0.0-20200807122248-f5cb4d19a4fe/go.mod h1:q7ebJwBFgDx4nP5jGhd+K9XgOIpKaNVh4RWpKmW61Gg=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
configv1listers "github.com/openshift/client-go/config/listers/config/v1"
operatorcontrolplaneclient "github.com/openshift/client-go/operatorcontrolplane/clientset/versioned"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/connectivitycheckcontroller"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourcehelper"
"github.com/openshift/library-go/pkg/operator/v1helpers"
Expand All @@ -30,71 +31,52 @@ import (
"github.com/openshift/cluster-openshift-apiserver-operator/pkg/operator/operatorclient"
)

type ConnectivityCheckController interface {
factory.Controller
type OpenshiftAPIServerConnectivityCheckController interface {
connectivitycheckcontroller.ConnectivityCheckController
}

func NewConnectivityCheckController(
func NewOpenshiftAPIServerConnectivityCheckController(
kubeClient kubernetes.Interface,
operatorClient v1helpers.OperatorClient,
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
configInformers configinformers.SharedInformerFactory,
operatorcontrolplaneClient *operatorcontrolplaneclient.Clientset,
recorder events.Recorder,
) ConnectivityCheckController {
c := &connectivityCheckController{
kubeClient: kubeClient,
operatorClient: operatorClient,
connectivityCheckGenerator: connectivityCheckTemplateProvider{
operatorcontrolplaneClient: operatorcontrolplaneClient,
endpointsLister: kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Endpoints().Lister(),
serviceLister: kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Services().Lister(),
podLister: kubeInformersForNamespaces.InformersFor("openshift-apiserver").Core().V1().Pods().Lister(),
nodeLister: kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes().Lister(),
infrastructureLister: configInformers.Config().V1().Infrastructures().Lister(),
},
) OpenshiftAPIServerConnectivityCheckController {
c := openshiftAPIServerConnectivityCheckController{
ConnectivityCheckController: connectivitycheckcontroller.NewConnectivityCheckController(
operatorclient.TargetNamespace,
operatorClient,
operatorcontrolplaneClient,
[]factory.Informer{
operatorClient.Informer(),
kubeInformersForNamespaces.InformersFor("openshift-apiserver").Core().V1().Pods().Informer(),
kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Endpoints().Informer(),
kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Services().Informer(),
kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes().Informer(),
configInformers.Config().V1().Infrastructures().Informer(),
},
recorder,
),
}
generator := &connectivityCheckTemplateProvider{
operatorClient: operatorClient,
operatorcontrolplaneClient: operatorcontrolplaneClient,
endpointsLister: kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Endpoints().Lister(),
serviceLister: kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Services().Lister(),
podLister: kubeInformersForNamespaces.InformersFor("openshift-apiserver").Core().V1().Pods().Lister(),
nodeLister: kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes().Lister(),
infrastructureLister: configInformers.Config().V1().Infrastructures().Lister(),
}
c.Controller = factory.New().
WithSync(c.Sync).
WithInformers(
operatorClient.Informer(),
kubeInformersForNamespaces.InformersFor("openshift-apiserver").Core().V1().Pods().Informer(),
kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Endpoints().Informer(),
kubeInformersForNamespaces.InformersFor("openshift-kube-apiserver").Core().V1().Services().Informer(),
kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes().Informer(),
configInformers.Config().V1().Infrastructures().Informer(),
).
ToController("ConnectivityCheckController", recorder.WithComponentSuffix("connectivity-check-controller"))
return c
return c.WithPodNetworkConnectivityCheckFn(generator.generate)
}

type connectivityCheckController struct {
factory.Controller
kubeClient kubernetes.Interface
operatorClient v1helpers.OperatorClient
connectivityCheckGenerator connectivityCheckTemplateProvider
}

func (c *connectivityCheckController) Sync(ctx context.Context, syncContext factory.SyncContext) error {
operatorSpec, _, _, err := c.operatorClient.GetOperatorState()
if err != nil {
return err
}
switch operatorSpec.ManagementState {
case operatorv1.Managed:
case operatorv1.Unmanaged:
return nil
case operatorv1.Removed:
return nil
default:
syncContext.Recorder().Warningf("ManagementStateUnknown", "Unrecognized operator management state %q", operatorSpec.ManagementState)
return nil
}
c.connectivityCheckGenerator.getPodNetworkConnectivityChecks(ctx, operatorSpec, syncContext.Recorder())
return nil
type openshiftAPIServerConnectivityCheckController struct {
connectivitycheckcontroller.ConnectivityCheckController
}

type connectivityCheckTemplateProvider struct {
operatorClient v1helpers.OperatorClient
operatorcontrolplaneClient *operatorcontrolplaneclient.Clientset
endpointsLister corev1listers.EndpointsLister
serviceLister corev1listers.ServiceLister
Expand All @@ -103,11 +85,15 @@ type connectivityCheckTemplateProvider struct {
infrastructureLister configv1listers.InfrastructureLister
}

func (c *connectivityCheckTemplateProvider) generate(ctx context.Context, syncContext factory.SyncContext) ([]*v1alpha1.PodNetworkConnectivityCheck, error) {
return nil, nil
}

func (c *connectivityCheckTemplateProvider) getPodNetworkConnectivityChecks(ctx context.Context, operatorSpec *operatorv1.OperatorSpec, recorder events.Recorder) {

var templates []*v1alpha1.PodNetworkConnectivityCheck
// each storage endpoint
templates = append(templates, c.getTemplatesForStorageChecks(operatorSpec, recorder)...)
templates = append(templates, c.getTemplatesForStorageChecks(recorder)...)
// kas service IP
templates = append(templates, c.getTemplatesForKubernetesServiceMonitorService(recorder)...)
// kas default service IP
Expand Down Expand Up @@ -234,7 +220,12 @@ func (c *connectivityCheckTemplateProvider) listAddressesForKubeAPIServerService
return results, nil
}

func (c *connectivityCheckTemplateProvider) getTemplatesForStorageChecks(operatorSpec *operatorv1.OperatorSpec, recorder events.Recorder) []*v1alpha1.PodNetworkConnectivityCheck {
func (c *connectivityCheckTemplateProvider) getTemplatesForStorageChecks(recorder events.Recorder) []*v1alpha1.PodNetworkConnectivityCheck {
operatorSpec, _, _, err := c.operatorClient.GetOperatorState()
if err != nil {
recorder.Warningf("EndpointDetectionFailure", "unable to determine storage endpoints: %v", err)
return nil
}
var templates []*v1alpha1.PodNetworkConnectivityCheck
for _, endpointInfo := range c.listAddressesForStorageEndpoints(operatorSpec, recorder) {
templates = append(templates, NewPodNetworkConnectivityCheckTemplate(
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
configInformers.Config().V1().Images().Informer(),
).WithStaticResourcesController(
"APIServerStaticResources",
libgoassets.WithAuditPolicies(operatorclient.TargetNamespace, v311_00_assets.Asset),
libgoassets.WithAuditPolicies("audit", operatorclient.TargetNamespace, v311_00_assets.Asset),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

[]string{
"v3.11.0/openshift-apiserver/ns.yaml",
"v3.11.0/openshift-apiserver/apiserver-clusterrolebinding.yaml",
Expand Down Expand Up @@ -275,7 +275,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
kubeInformersForNamespaces,
controllerConfig.EventRecorder,
)
auditPolicyPahGetter, err := libgoassets.NewAuditPolicyPathGetter()
auditPolicyPahGetter, err := libgoassets.NewAuditPolicyPathGetter("/var/run/configmaps/audit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good.

if err != nil {
return err
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
controllerConfig.Server.Handler.NonGoRestfulMux.Handle("/debug/controllers/resourcesync", debugHandler)
}

connectivityCheckController := connectivitycheckcontroller.NewConnectivityCheckController(
connectivityCheckController := connectivitycheckcontroller.NewOpenshiftAPIServerConnectivityCheckController(
kubeClient,
operatorClient,
kubeInformersForNamespaces,
Expand Down

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

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

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