Skip to content

Commit

Permalink
capacity: separate flags for mode and immediate binding
Browse files Browse the repository at this point in the history
`--enable-capacity` was originally designed to be a multi-value
boolean map. After removing options from it, replacing it with a
single-value string makes more sense.
  • Loading branch information
pohly committed Aug 17, 2020
1 parent f1f5c6f commit 1feefc7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 173 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ See the [storage capacity section](#capacity-support) below for details.

* `--capacity-poll-interval <interval>`: How long the external-provisioner waits before checking for storage capacity changes. Defaults to `1m`.

* `--enable-capacity <enumeration>`: Enables producing CSIStorageCapacity objects with capacity information from the driver's GetCapacity call. Can be given more than once and/or with comma-separated values. Currently supported: --enable-capacity=central,immediate-binding.
* `--capacity-controller-deployment-mode central|none`: Enables producing CSIStorageCapacity objects with capacity information from the driver's GetCapacity call. 'central' is currently the only supported mode. Use it when there is just one active provisioner in the cluster. Defaults to `none`.

* `--capacity-ownerref-level <levels>`: The level indicates the number of objects that need to be traversed starting from the pod identified by the POD_NAME and POD_NAMESPACE environment variables to reach the owning object for CSIStorageCapacity objects: 0 for the pod itself, 1 for a StatefulSet, 2 for a Deployment, etc. Defaults to `1` (= StatefulSet).

* `--capacity-for-immediate-binding <bool>`: Enables producing capacity information for storage classes with immediate binding. Not needed for the Kubernetes scheduler, maybe useful for other consumers or for debugging. Defaults to `false`.

#### Other recognized arguments
* `--feature-gates <gates>`: A set of comma separated `<feature-name>=<true|false>` pairs that describe feature gates for alpha/experimental features. See [list of features](#feature-status) or `--help` output for list of recognized features. Example: `--feature-gates Topology=true` to enable Topology feature that's disabled by default.

Expand Down
17 changes: 9 additions & 8 deletions cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ var (
kubeAPIQPS = flag.Float32("kube-api-qps", 5, "QPS to use while communicating with the kubernetes apiserver. Defaults to 5.0.")
kubeAPIBurst = flag.Int("kube-api-burst", 10, "Burst to use while communicating with the kubernetes apiserver. Defaults to 10.")

capacityFeatures = func() *capacity.Features {
capacity := &capacity.Features{}
flag.Var(capacity, "enable-capacity", "Enables producing CSIStorageCapacity objects with capacity information from the driver's GetCapacity call. Can be given more than once and/or with comma-separated values. Currently supported: --enable-capacity=central,immediate-binding.")
return capacity
capacityMode = func() *capacity.DeploymentMode {
mode := capacity.DeploymentModeNone
flag.Var(&mode, "capacity-controller-deployment-mode", "Enables producing CSIStorageCapacity objects with capacity information from the driver's GetCapacity call. 'central' is currently the only supported mode. Use it when there is just one active provisioner in the cluster.")
return &mode
}()
capacityPollInterval = flag.Duration("capacity-poll-interval", time.Minute, "How long the external-provisioner waits before checking for storage capacity changes.")
capacityOwnerrefLevel = flag.Int("capacity-ownerref-level", 1, "The level indicates the number of objects that need to be traversed starting from the pod identified by the POD_NAME and POD_NAMESPACE environment variables to reach the owning object for CSIStorageCapacity objects: 0 for the pod itself, 1 for a StatefulSet, 2 for a Deployment, etc.")
capacityImmediateBinding = flag.Bool("capacity-for-immediate-binding", false, "Enables producing capacity information for storage classes with immediate binding. Not needed for the Kubernetes scheduler, maybe useful for other consumers or for debugging.")
capacityPollInterval = flag.Duration("capacity-poll-interval", time.Minute, "How long the external-provisioner waits before checking for storage capacity changes.")
capacityOwnerrefLevel = flag.Int("capacity-ownerref-level", 1, "The level indicates the number of objects that need to be traversed starting from the pod identified by the POD_NAME and POD_NAMESPACE environment variables to reach the owning object for CSIStorageCapacity objects: 0 for the pod itself, 1 for a StatefulSet, 2 for a Deployment, etc.")

featureGates map[string]bool
provisionController *controller.ProvisionController
Expand Down Expand Up @@ -282,7 +283,7 @@ func main() {
)

var capacityController *capacity.Controller
if (*capacityFeatures)[capacity.FeatureCentral] {
if *capacityMode == capacity.DeploymentModeCentral {
podName := os.Getenv("POD_NAME")
namespace := os.Getenv("POD_NAMESPACE")
if podName == "" || namespace == "" {
Expand Down Expand Up @@ -326,7 +327,7 @@ func main() {
factory.Storage().V1().StorageClasses(),
factoryForNamespace.Storage().V1alpha1().CSIStorageCapacities(),
*capacityPollInterval,
(*capacityFeatures)[capacity.FeatureImmediateBinding],
*capacityImmediateBinding,
)
}

Expand Down
83 changes: 0 additions & 83 deletions pkg/capacity/features.go

This file was deleted.

81 changes: 0 additions & 81 deletions pkg/capacity/features_test.go

This file was deleted.

63 changes: 63 additions & 0 deletions pkg/capacity/mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2020 The Kubernetes 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 capacity

import (
"errors"
"strings"

flag "github.com/spf13/pflag"
)

// DeploymentMode determines how the capacity controller operates.
type DeploymentMode string

const (
// DeploymentModeCentral enables the mode where there is only one
// external-provisioner actively running in the cluster which
// talks to the CSI driver's controller service.
DeploymentModeCentral = DeploymentMode("central")

// DeploymentModeLocal enables the mode where external-provisioner
// is deployed on each node. Not implemented yet.
DeploymentModeLocal = DeploymentMode("local")

// DeploymentModeNone disables capacity support.
DeploymentModeNone = DeploymentMode("none")
)

// Set enables the named features. Multiple features can be listed, separated by commas,
// with optional whitespace.
func (mode *DeploymentMode) Set(value string) error {
switch DeploymentMode(value) {
case DeploymentModeCentral, DeploymentModeNone:
*mode = DeploymentMode(value)
default:
return errors.New("invalid value")
}
return nil
}

func (mode *DeploymentMode) String() string {
return string(*mode)
}

func (mode *DeploymentMode) Type() string {
return strings.Join([]string{string(DeploymentModeCentral), string(DeploymentModeNone)}, "|")
}

var _ flag.Value = new(DeploymentMode)

0 comments on commit 1feefc7

Please sign in to comment.