Skip to content

Commit

Permalink
pkg: drop techpreview gate for collection profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
  • Loading branch information
rexagod committed Jul 18, 2023
1 parent 6c0bb4f commit cdececc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
32 changes: 12 additions & 20 deletions pkg/manifests/config.go
Expand Up @@ -190,7 +190,7 @@ func (cps CollectionProfiles) String() string {
return sb.String()
}

func NewConfig(content io.Reader, tp bool) (*Config, error) {
func NewConfig(content io.Reader) (*Config, error) {
c := Config{}
cmc := defaultClusterMonitoringConfiguration()
err := k8syaml.NewYAMLOrJSONDecoder(content, 4096).Decode(&cmc)
Expand All @@ -201,25 +201,17 @@ func NewConfig(content io.Reader, tp bool) (*Config, error) {
res := &c
res.applyDefaults()
c.UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig()
// The operator should only create some manifests if techPreview is enabled
c.TechPreview = tp

if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile != FullCollectionProfile && !tp {
return nil, errors.Wrap(ErrConfigValidation, "collectionProfiles is a TechPreview feature, to be able to use a profile different from the default (\"full\") please enable TechPreview")
}

// Validate the configured collection profile iff tech preview is enabled, even if the default profile is set.
if tp {
for _, profile := range SupportedCollectionProfiles {
var v float64
if profile == c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile {
v = 1
}
metrics.CollectionProfile.WithLabelValues(string(profile)).Set(v)
}
if !slices.Contains(SupportedCollectionProfiles, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile) {
return nil, errors.Wrap(ErrConfigValidation, fmt.Sprintf(`%q is not supported, supported collection profiles are: %q`, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile, SupportedCollectionProfiles.String()))
// Validate the configured collection profile.
for _, profile := range SupportedCollectionProfiles {
var v float64
if profile == c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile {
v = 1
}
metrics.CollectionProfile.WithLabelValues(string(profile)).Set(v)
}
if !slices.Contains(SupportedCollectionProfiles, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile) {
return nil, errors.Wrap(ErrConfigValidation, fmt.Sprintf(`%q is not supported, supported collection profiles are: %q`, c.ClusterMonitoringConfiguration.PrometheusK8sConfig.CollectionProfile, SupportedCollectionProfiles.String()))
}

return res, nil
Expand Down Expand Up @@ -460,12 +452,12 @@ func calculateBodySizeLimit(podCapacity int) string {
// structure that facilitates programmatical checks of that configuration. The
// content of the data structure might change if TechPreview is enabled (tp), as
// some features are only meant for TechPreview.
func NewConfigFromString(content string, tp bool) (*Config, error) {
func NewConfigFromString(content string) (*Config, error) {
if content == "" {
return NewDefaultConfig(), nil
}

return NewConfig(bytes.NewBuffer([]byte(content)), tp)
return NewConfig(bytes.NewBuffer([]byte(content)))
}

func NewDefaultConfig() *Config {
Expand Down
11 changes: 3 additions & 8 deletions pkg/operator/operator.go
Expand Up @@ -897,7 +897,7 @@ func (o *Operator) loadUserWorkloadConfig(ctx context.Context) (*manifests.UserW
return uwc, nil
}

func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
func (o *Operator) loadConfig(key string) (*manifests.Config, error) {
obj, found, err := o.cmapInf.GetStore().GetByKey(key)
if err != nil {
return nil, errors.Wrap(err, "an error occurred when retrieving the Cluster Monitoring ConfigMap")
Expand All @@ -915,7 +915,7 @@ func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
return nil, errors.New("the Cluster Monitoring ConfigMap doesn't contain a 'config.yaml' key")
}

cParsed, err := manifests.NewConfigFromString(configContent, tp)
cParsed, err := manifests.NewConfigFromString(configContent)
if err != nil {
return nil, errors.Wrap(err, "the Cluster Monitoring ConfigMap could not be parsed")
}
Expand All @@ -924,12 +924,7 @@ func (o *Operator) loadConfig(key string, tp bool) (*manifests.Config, error) {
}

func (o *Operator) Config(ctx context.Context, key string) (*manifests.Config, error) {
tp, err := o.client.TechPreviewEnabled(ctx)
if err != nil {
return nil, err
}

c, err := o.loadConfig(key, tp)
c, err := o.loadConfig(key)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit cdececc

Please sign in to comment.