Skip to content

Commit

Permalink
Separate the controller for cross-namespace snapshot provisioning fro…
Browse files Browse the repository at this point in the history
…m normal provisioning
  • Loading branch information
mkimuram committed Jun 6, 2022
1 parent 90b1066 commit 75eacaa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM gcr.io/distroless/static:latest
LABEL maintainers="Kubernetes Authors"
LABEL description="CSI External Provisioner"
ARG binary=./bin/csi-provisioner
LABEL description="CSI Cross-namespace Snapshot Provisioner"
ARG binary=./bin/csi-xns-ss-provisioner

COPY ${binary} csi-provisioner
ENTRYPOINT ["/csi-provisioner"]
COPY ${binary} csi-xns-ss-provisioner
ENTRYPOINT ["/csi-xns-ss-provisioner"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

CMDS=csi-provisioner
CMDS=csi-xns-ss-provisioner
all: build

include release-tools/build.make
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions deploy/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: csi-provisioner
name: csi-xns-ss-provisioner
spec:
replicas: 3
selector:
matchLabels:
app: csi-provisioner
app: csi-xns-ss-provisioner
template:
metadata:
labels:
app: csi-provisioner
app: csi-xns-ss-provisioner
spec:
serviceAccount: csi-provisioner
serviceAccount: csi-xns-ss-provisioner
containers:
- name: csi-provisioner
image: gcr.io/k8s-staging-sig-storage/csi-provisioner:canary
- name: csi-xns-ss-provisioner
image: gcr.io/k8s-staging-sig-storage/csi-xns-ss-provisioner:canary
args:
- "--csi-address=$(ADDRESS)"
- "--leader-election"
Expand Down
24 changes: 6 additions & 18 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,31 @@ var (
}

provisionerSecretParams = secretParamsMap{
name: "Provisioner",
name: "Provisioner",
deprecatedSecretNameKey: provisionerSecretNameKey,
deprecatedSecretNamespaceKey: provisionerSecretNamespaceKey,
secretNameKey: prefixedProvisionerSecretNameKey,
secretNamespaceKey: prefixedProvisionerSecretNamespaceKey,
}

nodePublishSecretParams = secretParamsMap{
name: "NodePublish",
name: "NodePublish",
deprecatedSecretNameKey: nodePublishSecretNameKey,
deprecatedSecretNamespaceKey: nodePublishSecretNamespaceKey,
secretNameKey: prefixedNodePublishSecretNameKey,
secretNamespaceKey: prefixedNodePublishSecretNamespaceKey,
}

controllerPublishSecretParams = secretParamsMap{
name: "ControllerPublish",
name: "ControllerPublish",
deprecatedSecretNameKey: controllerPublishSecretNameKey,
deprecatedSecretNamespaceKey: controllerPublishSecretNamespaceKey,
secretNameKey: prefixedControllerPublishSecretNameKey,
secretNamespaceKey: prefixedControllerPublishSecretNamespaceKey,
}

nodeStageSecretParams = secretParamsMap{
name: "NodeStage",
name: "NodeStage",
deprecatedSecretNameKey: nodeStageSecretNameKey,
deprecatedSecretNamespaceKey: nodeStageSecretNamespaceKey,
secretNameKey: prefixedNodeStageSecretNameKey,
Expand Down Expand Up @@ -549,22 +549,14 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
}

switch claim.Spec.DataSource.Kind {
case snapshotKind:
if *(claim.Spec.DataSource.APIGroup) != snapshotAPIGroup {
return nil, controller.ProvisioningFinished, fmt.Errorf("the PVC source does not belong to the right APIGroup. Expected %s, Got %s", snapshotAPIGroup, *(claim.Spec.DataSource.APIGroup))
}
rc.snapshot = true
case snapshotLinkKind:
if *(claim.Spec.DataSource.APIGroup) != transferAPIGroup {
return nil, controller.ProvisioningFinished, fmt.Errorf("the PVC source does not belong to the right APIGroup. Expected %s, Got %s", transferAPIGroup, *(claim.Spec.DataSource.APIGroup))
}
rc.snapshot = true
case pvcKind:
rc.clone = true
default:
// DataSource is not VolumeSnapshot and PVC
// Assume external data populator to create the volume, and there is no more work for us to do
p.eventRecorder.Event(claim, v1.EventTypeNormal, "Provisioning", fmt.Sprintf("Assuming an external populator will provision the volume"))
// DataSource is not snapshotLink
// Assume provisioner or external data populator to create the volume, and there is no more work for us to do
return nil, controller.ProvisioningFinished, &controller.IgnoredError{
Reason: fmt.Sprintf("data source (%s) is not handled by the provisioner, assuming an external populator will provision it",
claim.Spec.DataSource.Kind),
Expand Down Expand Up @@ -947,12 +939,8 @@ func removePrefixedParameters(param map[string]string) (map[string]string, error
// an appropriate implementation function
func (p *csiProvisioner) getVolumeContentSource(ctx context.Context, claim *v1.PersistentVolumeClaim, sc *storagev1.StorageClass) (*csi.VolumeContentSource, error) {
switch claim.Spec.DataSource.Kind {
case snapshotKind:
return p.getSnapshotSource(ctx, claim, sc)
case snapshotLinkKind:
return p.getSnapshotLinkSource(ctx, claim, sc)
case pvcKind:
return p.getPVCSource(ctx, claim, sc)
default:
// For now we shouldn't pass other things to this function, but treat it as a noop and extend as needed
return nil, nil
Expand Down

0 comments on commit 75eacaa

Please sign in to comment.