-
Notifications
You must be signed in to change notification settings - Fork 39
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
controller: add support for global persistent configuration #364
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: csi-addons-config | ||
# replace the namespace with the namespace where the operator is deployed. | ||
namespace: csi-addons-system | ||
data: | ||
"reclaim-space-timeout": "3m" | ||
"max-concurrent-reconciles": "100" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# CSI-Addons Operator Configuration | ||
|
||
CSI-Addons Operator can consume configuration from a ConfigMap named `csi-addons-config` | ||
in the same namespace as the operator. This enables configuration of the operator to persist across | ||
upgrades. The ConfigMap can support the following configuration options: | ||
nixpanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
| Option | Default value | Description | | ||
| ----------------------------- | --------------- | --------------------------------------------- | | ||
| `reclaim-space-timeout` | `"3m"` | Timeout for reclaimspace operation | | ||
| `max-concurrent-reconciles` | `"100"` | Maximum number of concurrent reconciles | | ||
|
||
[`csi-addons-config` ConfigMap](../deploy/controller/csi-addons-config.yaml) is provided as an example. | ||
|
||
> Note: The operator pod needs to be restarted for any change in configuration to take effect. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2023 The Kubernetes-CSI-Addons Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// Config holds the configuration options that | ||
// can be overrrided via a config file. | ||
type Config struct { | ||
Namespace string | ||
ReclaimSpaceTimeout time.Duration | ||
MaxConcurrentReconciles int | ||
} | ||
|
||
const ( | ||
csiAddonsConfigMapName = "csi-addons-config" | ||
ReclaimSpaceTimeoutKey = "reclaim-space-timeout" | ||
MaxConcurrentReconcilesKey = "max-concurrent-reconciles" | ||
defaultNamespace = "csi-addons-system" | ||
defaultMaxConcurrentReconciles = 100 | ||
defaultReclaimSpaceTimeout = time.Minute * 3 | ||
) | ||
|
||
// NewConfig returns a new Config object with default values. | ||
func NewConfig() Config { | ||
return Config{ | ||
Namespace: defaultNamespace, | ||
ReclaimSpaceTimeout: defaultReclaimSpaceTimeout, | ||
MaxConcurrentReconciles: defaultMaxConcurrentReconciles, | ||
} | ||
} | ||
|
||
// ReadConfigFile fetches the config file and updates the | ||
// config options with values read from the config map. | ||
func (cfg *Config) ReadConfigMap(ctx context.Context, kubeClient *kubernetes.Clientset) error { | ||
cm, err := kubeClient.CoreV1().ConfigMaps(cfg.Namespace). | ||
Get(ctx, csiAddonsConfigMapName, metav1.GetOptions{}) | ||
if kerrors.IsNotFound(err) { | ||
return nil | ||
} | ||
if err != nil { | ||
return fmt.Errorf("failed to get configmap %q: %w", csiAddonsConfigMapName, err) | ||
} | ||
|
||
return cfg.readConfig(cm.Data) | ||
} | ||
|
||
// readConfigFile reads the config dataMap and updates the | ||
// config options. | ||
func (cfg *Config) readConfig(dataMap map[string]string) error { | ||
for key, val := range dataMap { | ||
switch key { | ||
case ReclaimSpaceTimeoutKey: | ||
timeout, err := time.ParseDuration(val) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse key %q value %q as duration: %w", | ||
ReclaimSpaceTimeoutKey, val, err) | ||
} | ||
cfg.ReclaimSpaceTimeout = timeout | ||
|
||
case MaxConcurrentReconcilesKey: | ||
maxConcurrentReconciles, err := strconv.Atoi(val) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse key %q value %q as int: %w", | ||
MaxConcurrentReconcilesKey, val, err) | ||
} | ||
cfg.MaxConcurrentReconciles = maxConcurrentReconciles | ||
|
||
default: | ||
return fmt.Errorf("unknown config key %q", key) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
env
section is missing here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its added above in manager.yaml . https://github.com/csi-addons/kubernetes-csi-addons/pull/364/files/fcaf7571fe7ee850410e6f2da6fb853daa0a023f#diff-ce0d597a9e5f20a8fe61c3ba5e6185a6b90cfef2c00bb5b5ef3e97b15b79f480
This yaml patches & overrides the manager container args, so I added the namespace arg here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right!