Skip to content

Commit

Permalink
OCPBUGS-14771: run an extra config informer in the tech preview (open…
Browse files Browse the repository at this point in the history
…shift#792)

* OCPBUGS-14771 run an extra config informer in the tech preview

* add resync time
  • Loading branch information
tremes authored and JoaoFula committed Jan 23, 2024
1 parent ee2b05b commit f4d489f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
8 changes: 4 additions & 4 deletions pkg/anonymization/anonymizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Anonymizer struct {
ipNetworkRegex *regexp.Regexp
secretsClient corev1client.SecretInterface
secretConfigurator configobserver.Configurator
apiConfigurator configobserver.APIConfigObserver
apiConfigurator configobserver.InsightsDataGatherObserver
configClient configv1client.ConfigV1Interface
networkClient networkv1client.NetworkV1Interface
gatherKubeClient kubernetes.Interface
Expand All @@ -104,7 +104,7 @@ func NewAnonymizer(clusterBaseDomain string,
networks []string,
secretsClient corev1client.SecretInterface,
secretConfigurator configobserver.Configurator,
apiConfigurator configobserver.APIConfigObserver) (*Anonymizer, error) {
apiConfigurator configobserver.InsightsDataGatherObserver) (*Anonymizer, error) {
cidrs, err := k8snet.ParseCIDRs(networks)
if err != nil {
return nil, err
Expand Down Expand Up @@ -138,7 +138,7 @@ func NewAnonymizerFromConfigClient(
configClient configv1client.ConfigV1Interface,
networkClient networkv1client.NetworkV1Interface,
secretConfigurator configobserver.Configurator,
apiConfigurator configobserver.APIConfigObserver,
apiConfigurator configobserver.InsightsDataGatherObserver,
) (*Anonymizer, error) {
baseDomain, err := utils.GetClusterBaseDomain(ctx, configClient)
if err != nil {
Expand Down Expand Up @@ -322,7 +322,7 @@ func NewAnonymizerFromConfig(
gatherProtoKubeConfig *rest.Config,
protoKubeConfig *rest.Config,
secretConfigurator configobserver.Configurator,
apiConfigurator configobserver.APIConfigObserver,
apiConfigurator configobserver.InsightsDataGatherObserver,
) (*Anonymizer, error) {
kubeClient, err := kubernetes.NewForConfig(protoKubeConfig)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package configobserver
import (
"context"
"sync"
"time"

"github.com/openshift/api/config/v1alpha1"
configCliv1alpha1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1alpha1"
Expand All @@ -15,32 +16,30 @@ import (
"k8s.io/klog/v2"
)

type APIConfigObserver interface {
type InsightsDataGatherObserver interface {
factory.Controller
GatherConfig() *v1alpha1.GatherConfig
GatherDataPolicy() *v1alpha1.DataPolicy
GatherDisabled() bool
}

type APIConfigController struct {
type insightsDataGatherController struct {
factory.Controller
lock sync.Mutex
listeners map[chan *v1alpha1.GatherConfig]struct{}
configV1Alpha1Cli *configCliv1alpha1.ConfigV1alpha1Client
gatherConfig *v1alpha1.GatherConfig
}

func NewAPIConfigObserver(kubeConfig *rest.Config,
func NewInsightsDataGatherObserver(kubeConfig *rest.Config,
eventRecorder events.Recorder,
configInformer configinformers.SharedInformerFactory) (APIConfigObserver, error) {
configInformer configinformers.SharedInformerFactory) (InsightsDataGatherObserver, error) {
inf := configInformer.Config().V1alpha1().InsightsDataGathers().Informer()
configV1Alpha1Cli, err := configCliv1alpha1.NewForConfig(kubeConfig)
if err != nil {
return nil, err
}
c := &APIConfigController{
c := &insightsDataGatherController{
configV1Alpha1Cli: configV1Alpha1Cli,
listeners: make(map[chan *v1alpha1.GatherConfig]struct{}),
}

insightDataGatherConf, err := c.configV1Alpha1Cli.InsightsDataGathers().Get(context.Background(), "cluster", metav1.GetOptions{})
Expand All @@ -51,42 +50,43 @@ func NewAPIConfigObserver(kubeConfig *rest.Config,

ctrl := factory.New().WithInformers(inf).
WithSync(c.sync).
ToController("InsightConfigController", eventRecorder)
ResyncEvery(2*time.Minute).
ToController("InsightsDataGatherObserver", eventRecorder)
c.Controller = ctrl
return c, nil
}

func (a *APIConfigController) sync(ctx context.Context, _ factory.SyncContext) error {
insightDataGatherConf, err := a.configV1Alpha1Cli.InsightsDataGathers().Get(ctx, "cluster", metav1.GetOptions{})
func (i *insightsDataGatherController) sync(ctx context.Context, scx factory.SyncContext) error {
insightDataGatherConf, err := i.configV1Alpha1Cli.InsightsDataGathers().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
return err
}
a.gatherConfig = &insightDataGatherConf.Spec.GatherConfig
i.gatherConfig = &insightDataGatherConf.Spec.GatherConfig
return nil
}

// GatherConfig provides the complete gather config in a thread-safe way.
func (a *APIConfigController) GatherConfig() *v1alpha1.GatherConfig {
a.lock.Lock()
defer a.lock.Unlock()
return a.gatherConfig
func (i *insightsDataGatherController) GatherConfig() *v1alpha1.GatherConfig {
i.lock.Lock()
defer i.lock.Unlock()
return i.gatherConfig
}

// GatherDisabled tells whether data gathering is disabled or not
func (a *APIConfigController) GatherDisabled() bool {
a.lock.Lock()
defer a.lock.Unlock()
func (i *insightsDataGatherController) GatherDisabled() bool {
i.lock.Lock()
defer i.lock.Unlock()

if utils.StringInSlice("all", a.gatherConfig.DisabledGatherers) ||
utils.StringInSlice("ALL", a.gatherConfig.DisabledGatherers) {
if utils.StringInSlice("all", i.gatherConfig.DisabledGatherers) ||
utils.StringInSlice("ALL", i.gatherConfig.DisabledGatherers) {
return true
}
return false
}

// GatherDataPolicy provides DataPolicy attribute value defined in the API
func (a *APIConfigController) GatherDataPolicy() *v1alpha1.DataPolicy {
a.lock.Lock()
defer a.lock.Unlock()
return &a.gatherConfig.DataPolicy
func (i *insightsDataGatherController) GatherDataPolicy() *v1alpha1.DataPolicy {
i.lock.Lock()
defer i.lock.Unlock()
return &i.gatherConfig.DataPolicy
}
18 changes: 11 additions & 7 deletions pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
return fmt.Errorf("can't create --path: %v", err)
}
}
var apiConfigObserver configobserver.APIConfigObserver
var insightsDataGatherObserver configobserver.InsightsDataGatherObserver
if insightsConfigAPIEnabled {
apiConfigObserver, err = configobserver.NewAPIConfigObserver(gatherKubeConfig, controller.EventRecorder, configInformers)
configInformersForTechPreview := configv1informers.NewSharedInformerFactory(configClient, 10*time.Minute)
insightsDataGatherObserver, err = configobserver.NewInsightsDataGatherObserver(gatherKubeConfig,
controller.EventRecorder, configInformersForTechPreview)
if err != nil {
return err
}
go apiConfigObserver.Run(ctx, 1)

go insightsDataGatherObserver.Run(ctx, 1)
go configInformersForTechPreview.Start(ctx.Done())
}

// secretConfigObserver synthesizes all config into the status reporter controller
Expand All @@ -135,11 +139,11 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller

// the status controller initializes the cluster operator object and retrieves
// the last sync time, if any was set
statusReporter := status.NewController(configClient.ConfigV1(), secretConfigObserver, apiConfigObserver, os.Getenv("POD_NAMESPACE"))
statusReporter := status.NewController(configClient.ConfigV1(), secretConfigObserver, insightsDataGatherObserver, os.Getenv("POD_NAMESPACE"))

// anonymizer is responsible for anonymizing sensitive data, it can be configured to disable specific anonymization
anonymizer, err := anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig,
gatherProtoKubeConfig, controller.ProtoKubeConfig, secretConfigObserver, apiConfigObserver)
gatherProtoKubeConfig, controller.ProtoKubeConfig, secretConfigObserver, insightsDataGatherObserver)
if err != nil {
// in case of an error anonymizer will be nil and anonymization will be just skipped
klog.Errorf(anonymization.UnableToCreateAnonymizerErrorMessage, err)
Expand Down Expand Up @@ -170,7 +174,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
gatherKubeConfig, gatherProtoKubeConfig, metricsGatherKubeConfig, alertsGatherKubeConfig, anonymizer,
secretConfigObserver, insightsClient,
)
periodicGather := periodic.New(secretConfigObserver, rec, gatherers, anonymizer, operatorClient.InsightsOperators(), apiConfigObserver)
periodicGather := periodic.New(secretConfigObserver, rec, gatherers, anonymizer, operatorClient.InsightsOperators(), insightsDataGatherObserver)
statusReporter.AddSources(periodicGather.Sources()...)

// check we can read IO container status and we are not in crash loop
Expand All @@ -186,7 +190,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller

// upload results to the provided client - if no client is configured reporting
// is permanently disabled, but if a client does exist the server may still disable reporting
uploader := insightsuploader.New(recdriver, insightsClient, secretConfigObserver, apiConfigObserver, statusReporter, initialDelay)
uploader := insightsuploader.New(recdriver, insightsClient, secretConfigObserver, insightsDataGatherObserver, statusReporter, initialDelay)
statusReporter.AddSources(uploader)

// start reporting status now that all controller loops are added as sources
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/periodic/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
// and flushes the recorder to create archives
type Controller struct {
secretConfigurator configobserver.Configurator
apiConfigurator configobserver.APIConfigObserver
apiConfigurator configobserver.InsightsDataGatherObserver
recorder recorder.FlushInterface
gatherers []gatherers.Interface
statuses map[string]controllerstatus.StatusController
Expand All @@ -56,7 +56,7 @@ func New(
listGatherers []gatherers.Interface,
anonymizer *anonymization.Anonymizer,
insightsOperatorCLI operatorv1client.InsightsOperatorInterface,
apiConfigurator configobserver.APIConfigObserver,
apiConfigurator configobserver.InsightsDataGatherObserver,
) *Controller {
statuses := make(map[string]controllerstatus.StatusController)

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/status/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Controller struct {

statusCh chan struct{}
secretConfigurator configobserver.Configurator
apiConfigurator configobserver.APIConfigObserver
apiConfigurator configobserver.InsightsDataGatherObserver

sources map[string]controllerstatus.StatusController
reported Reported
Expand All @@ -70,7 +70,7 @@ type Controller struct {
// NewController creates a statusMessage controller, responsible for monitoring the operators statusMessage and updating its cluster statusMessage accordingly.
func NewController(client configv1client.ConfigV1Interface,
secretConfigurator configobserver.Configurator,
apiConfigurator configobserver.APIConfigObserver,
apiConfigurator configobserver.InsightsDataGatherObserver,
namespace string) *Controller {
c := &Controller{
name: "insights",
Expand Down
4 changes: 2 additions & 2 deletions pkg/insights/insightsuploader/insightsuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Controller struct {
summarizer Summarizer
client *insightsclient.Client
secretConfigurator configobserver.Configurator
apiConfigurator configobserver.APIConfigObserver
apiConfigurator configobserver.InsightsDataGatherObserver
reporter StatusReporter
archiveUploaded chan struct{}
initialDelay time.Duration
Expand All @@ -45,7 +45,7 @@ type Controller struct {
func New(summarizer Summarizer,
client *insightsclient.Client,
secretconfigurator configobserver.Configurator,
apiConfigurator configobserver.APIConfigObserver,
apiConfigurator configobserver.InsightsDataGatherObserver,
statusReporter StatusReporter,
initialDelay time.Duration) *Controller {

Expand Down

0 comments on commit f4d489f

Please sign in to comment.