Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/controller/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package controller

import (
insightsv1alpha2 "github.com/openshift/api/insights/v1alpha2"
"github.com/openshift/insights-operator/pkg/config/configobserver"
)

// getCustomStoragePath determines a custom storage path by checking configuration sources
// in priority order:
// * DataGather CR specification (PersistentVolume.MountPath)
// * ConfigMap configuration (DataReporting.StoragePath)
func getCustomStoragePath(configAggregator configobserver.Interface, dataGatherCR *insightsv1alpha2.DataGather) string {
defaultPath := ""

// Get the default path from ConfigMap configuration
if configStoragePath := configAggregator.Config().DataReporting.StoragePath; configStoragePath != "" {
defaultPath = configStoragePath
}

if dataGatherCR == nil {
return defaultPath
}

if dataGatherCR.Spec.Storage == nil || dataGatherCR.Spec.Storage.Type != insightsv1alpha2.StorageTypePersistentVolume {
return defaultPath
}

if dataGatherCR.Spec.Storage.PersistentVolume != nil {
if storagePath := dataGatherCR.Spec.Storage.PersistentVolume.MountPath; storagePath != "" {
return storagePath
}
}

return defaultPath
}
29 changes: 0 additions & 29 deletions pkg/controller/gather_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,35 +585,6 @@ func createRemoteConfigConditions(
return
}

// getCustomStoragePath determines a custom storage path by checking configuration sources
// in priority order:
// * DataGather CR specification (PersistentVolume.MountPath)
// * ConfigMap configuration (DataReporting.StoragePath)
func getCustomStoragePath(configAggregator configobserver.Interface, dataGatherCR *insightsv1alpha2.DataGather) string {
defaultPath := ""

// Get the default path from ConfigMap configuration
if configStoragePath := configAggregator.Config().DataReporting.StoragePath; configStoragePath != "" {
defaultPath = configStoragePath
}

if dataGatherCR == nil {
return defaultPath
}

if dataGatherCR.Spec.Storage == nil || dataGatherCR.Spec.Storage.Type != insightsv1alpha2.StorageTypePersistentVolume {
return defaultPath
}

if dataGatherCR.Spec.Storage.PersistentVolume != nil {
if storagePath := dataGatherCR.Spec.Storage.PersistentVolume.MountPath; storagePath != "" {
return storagePath
}
}

return defaultPath
}

// boolToConditionStatus is a helper function to conver bool type
// tp the ConditionStatus type
func boolToConditionStatus(b bool) metav1.ConditionStatus {
Expand Down
19 changes: 12 additions & 7 deletions pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller

insightsConfigEnabled := featureGates.Enabled(features.FeatureGateInsightsConfig)

// ensure the insight snapshot directory exists
if _, err = os.Stat(s.StoragePath); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(s.StoragePath, 0o777); err != nil {
return fmt.Errorf("can't create --path: %v", err)
}
}

var techPreviewInformers *TechPreviewInformers
var insightsDataGatherObserver configobserver.InsightsDataGatherObserver
if insightsConfigEnabled {
Expand Down Expand Up @@ -200,6 +193,18 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
configAggregator := configobserver.NewConfigAggregator(secretConfigObserver, configMapObserver)
go configAggregator.Listen(ctx)

// additional configurations may exist besides the default one
if customPath := getCustomStoragePath(configAggregator, nil); customPath != "" {
s.StoragePath = customPath
}

// ensure the insight snapshot directory exists
if _, err = os.Stat(s.StoragePath); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(s.StoragePath, 0o777); err != nil {
return fmt.Errorf("can't create --path: %v", err)
}
}

// the status controller initializes the cluster operator object and retrieves
// the last sync time, if any was set
statusReporter := status.NewController(configClient.ConfigV1(), configAggregator,
Expand Down