Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#5 from huffmanca/rebase-0.3.0
Browse files Browse the repository at this point in the history
Rebase 0.3.0
  • Loading branch information
openshift-merge-robot authored Oct 16, 2019
2 parents 49315ac + e973d59 commit 2413e7d
Show file tree
Hide file tree
Showing 103 changed files with 8,791 additions and 2,914 deletions.
6 changes: 6 additions & 0 deletions .prow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

CSI_PROW_KUBERNETES_VERSION=latest
CSI_PROW_E2E_VERSION=master
. release-tools/prow.sh
main
File renamed without changes.
19 changes: 19 additions & 0 deletions CHANGELOG-0.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# v0.2.0


## Support Status

Alpha

## Changelog since v0.1.0

### New Features

- Implement CSI migration logic for volume resizing ([#39](https://github.com/kubernetes-csi/external-resizer/pull/39), [@leakingtapan](https://github.com/leakingtapan))


### Other Notable Changes

- Read volume expansion secrets from Persistent Volume Source ([#42](https://github.com/kubernetes-csi/external-resizer/pull/42), [@gnufied](https://github.com/gnufied))


18 changes: 18 additions & 0 deletions CHANGELOG-0.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# v0.3.0


## Support Status

Beta

## Changelog since v0.2.0

### New Features

None

### Bug Fixes

- Avoid concurrent processing of same PVCs ([#6](https://github.com/kubernetes-csi/external-resizer/pull/6), [@mlmhl](https://github.com/mlmhl))
- Exit on CSI gRPC conn loss ([#55](https://github.com/kubernetes-csi/external-resizer/pull/55), [@ggriffiths](https://github.com/kubernetes-csi/external-resizer/pull/55))
- Verify claimref associated with PVs before resizing ([#57](https://github.com/kubernetes-csi/external-resizer/pull/57), [@gnufied](https://github.com/gnufied))
2 changes: 1 addition & 1 deletion Dockerfile.openshift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.11 AS builder
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.12 AS builder
WORKDIR /go/src/github.com/kubernetes-csi/external-resizer
COPY . .
RUN make build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.openshift.rhel7
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.svc.ci.openshift.org/ocp/builder:golang-1.11 AS builder
FROM registry.svc.ci.openshift.org/ocp/builder:golang-1.12 AS builder
WORKDIR /go/src/github.com/kubernetes-csi/external-resizer
COPY . .
RUN make build
Expand Down
32 changes: 26 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
# go-tests = true
# unused-packages = true

[[constraint]]
[[override]]
name = "k8s.io/api"
version = "kubernetes-1.14.0"
branch = "release-1.15"

[[constraint]]
name = "k8s.io/apimachinery"
Expand Down
65 changes: 54 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,65 @@
# external-resizer
[![Build Status](https://travis-ci.org/kubernetes-csi/external-resizer.svg?branch=master)](https://travis-ci.org/kubernetes-csi/external-resizer)

This is an external Kubernetes controller which can expand volumes using CSI volume Drivers. It's under heavy development
and of alpha quality.
# CSI Resizer

# Build
The CSI `external-resizer` is a sidecar container that watches the Kubernetes API server for `PersistentVolumeClaim` updates and
triggers `ControllerExpandVolume` operations against a CSI endpoint if user requested more storage on `PersistentVolumeClaim` object.

## Overview

A storage provider that allows volume expansion after creation, may choose to implement volume expansion either via a
control-plane CSI RPC call or via node CSI RPC call or both as a two step process. The external-resizer is an external-controller that watches Kubernetes API server for `PersistentVolumeClaim` modifications and triggers CSI calls for control-plane volume-expansion. More details can be found on - [CSI Volume expansion](https://kubernetes-csi.github.io/docs/volume-expansion.html)

## Compatibility

This information reflects the head of this branch.

| Compatible with CSI Version | Container Image | Recommended K8s Version |
| ------------------------------------------------------------------------------------------ | -------------------------------| --------------- |
| [CSI Spec v1.1.0](https://github.com/container-storage-interface/spec/releases/tag/v1.1.0) | quay.io/k8scsi/csi-resizer | 1.16 |

```bash
make csi-resizer
```

# Running external resizer
## Feature status

## With mock driver
Currently all CSI volume expansion features are supported as Beta features by external-resizer.

```bash
./bin/csi-resizer --kubeconfig /var/run/kubernetes/admin.kubeconfig --csi-address /var/lib/kubelet/plugins/csi-mock/csi.sock
## Usage

It is necessary to create a new service account and give it enough privileges to run the external-resizer, see `deploy/kubernetes/rbac.yaml`. The resizer is then deployed as single Deployment as illustrated below:

```sh
kubectl create deploy/kubernetes/deployment.yaml
```

The external-resizer may run in the same pod with other external CSI controllers such as the external-attacher, external-snapshotter and/or external-provisioner.

Note that the external-resizer does not scale with more replicas. Only one external-resizer is elected as leader and running. The others are waiting for the leader to die. They re-elect a new active leader in ~15 seconds after death of the old leader.

### Command line options

#### Recommended optional arguments

* `--csi-address <path to CSI socket>`: This is the path to the CSI driver socket inside the pod that the external-resizer container will use to issue CSI operations (`/run/csi/socket` is used by default).

* `--leader-election`: Enables leader election. This is mandatory when there are multiple replicas of the same external-resizer running for one CSI driver. Only one of them may be active (=leader). A new leader will be re-elected when current leader dies or becomes unresponsive for ~15 seconds.

* `--leader-election-namespace`: Namespace where the leader election resource lives. Defaults to the pod namespace if not set.

* `---csiTimeout <duration>`: Timeout of all calls to CSI driver. It should be set to value that accommodates majority of `ControllerExpandVolume` calls. 15 seconds is used by default.

* `--workers <num>`: Number of simultaneously running `ControllerExpandVolume` operations. Default value is `10`.

#### Other recognized arguments

* `--kubeconfig <path>`: Path to Kubernetes client configuration that the external-resizer uses to connect to Kubernetes API server. When omitted, default token provided by Kubernetes will be used. This option is useful only when the external-resizer does not run as a Kubernetes pod, e.g. for debugging. Either this or `--master` needs to be set if the external-resizer is being run out of cluster.

* `--master <url>`: Master URL to build a client config from. When omitted, default token provided by Kubernetes will be used. This option is useful only when the external-resizer does not run as a Kubernetes pod, e.g. for debugging. Either this or `--kubeconfig` needs to be set if the external-resizer is being run out of cluster.

* `--version`: Prints current external-resizer version and quits.

* All glog / klog arguments are supported, such as `-v <log level>` or `-alsologtostderr`.


## Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
Expand Down
3 changes: 0 additions & 3 deletions deploy/kubernetes/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumeclaims/status"]
verbs: ["update", "patch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
Expand Down
54 changes: 44 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/kubernetes-csi/external-resizer/pkg/resizer"
"github.com/kubernetes-csi/external-resizer/pkg/util"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -123,12 +123,41 @@ func (ctrl *resizeController) updatePVC(oldObj, newObj interface{}) {
newSize := newPVC.Spec.Resources.Requests[v1.ResourceStorage]
oldSize := oldPVC.Spec.Resources.Requests[v1.ResourceStorage]

newResizerName := newPVC.Annotations[util.VolumeResizerKey]
oldResizerName := oldPVC.Annotations[util.VolumeResizerKey]

// We perform additional checks to avoid double processing of PVCs, as we will also receive Update event when:
// 1. Administrator or users may introduce other changes(such as add labels, modify annotations, etc.)
// unrelated to volume resize.
// 2. Informer will resync and send Update event periodically without any changes.
if newSize.Cmp(oldSize) > 0 {
//
// We add the PVC into work queue when the new size is larger then the old size
// or when the resizer name changes. This is needed for CSI migration for the follow two cases:
//
// 1. First time a migrated PVC is expanded:
// It does not yet have the annotation because annotation is only added by in-tree resizer when it receives a volume
// expansion request. So first update event that will be received by external-resizer will be ignored because it won't
// know how to support resizing of a "un-annotated" in-tree PVC. When in-tree resizer does add the annotation, a second
// update even will be received and we add the pvc to workqueue. If annotation matches the registered driver name in
// csi_resizer object, we proceeds with expansion internally or we discard the PVC.
// 2. An already expanded in-tree PVC:
// An in-tree PVC is resized with in-tree resizer. And later, CSI migration is turned on and resizer name is updated from
// in-tree resizer name to CSI driver name.
if newSize.Cmp(oldSize) > 0 || newResizerName != oldResizerName {
ctrl.addPVC(newObj)
} else {
// PVC's size not changed, so this Update event maybe caused by:
//
// 1. Administrators or users introduce other changes(such as add labels, modify annotations, etc.)
// unrelated to volume resize.
// 2. Informer resynced the PVC and send this Update event without any changes.
//
// If it is case 1, we can just discard this event. If case 2, we need to put it into the queue to
// perform a resync operation.
if newPVC.ResourceVersion == oldPVC.ResourceVersion {
// This is case 2.
ctrl.addPVC(newObj)
}
}
}

Expand Down Expand Up @@ -249,11 +278,16 @@ func (ctrl *resizeController) pvcNeedResize(pvc *v1.PersistentVolumeClaim) bool

// pvNeedResize returns true if a pv supports and also requests resize.
func (ctrl *resizeController) pvNeedResize(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) bool {
if !ctrl.resizer.CanSupport(pv) {
if !ctrl.resizer.CanSupport(pv, pvc) {
klog.V(4).Infof("Resizer %q doesn't support PV %q", ctrl.name, pv.Name)
return false
}

if (pv.Spec.ClaimRef == nil) || (pvc.Namespace != pv.Spec.ClaimRef.Namespace) || (pvc.UID != pv.Spec.ClaimRef.UID) {
klog.V(4).Infof("persistent volume is not bound to PVC being updated: %s", util.PVCKey(pvc))
return false
}

pvSize := pv.Spec.Capacity[v1.ResourceStorage]
requestSize := pvc.Spec.Resources.Requests[v1.ResourceStorage]
if pvSize.Cmp(requestSize) >= 0 {
Expand Down Expand Up @@ -350,12 +384,13 @@ func (ctrl *resizeController) markPVCResizeInProgress(pvc *v1.PersistentVolumeCl
return util.PatchPVCStatus(pvc, newPVC, ctrl.kubeClient)
}

func (ctrl *resizeController) markPVCResizeFinished(pvc *v1.PersistentVolumeClaim, newSize resource.Quantity) error {
func (ctrl *resizeController) markPVCResizeFinished(
pvc *v1.PersistentVolumeClaim,
newSize resource.Quantity) error {
newPVC := pvc.DeepCopy()
newPVC.Status.Capacity[v1.ResourceStorage] = newSize
newPVC.Status.Conditions = util.MergeResizeConditionsOfPVC(pvc.Status.Conditions, []v1.PersistentVolumeClaimCondition{})
_, err := util.PatchPVCStatus(pvc, newPVC, ctrl.kubeClient)
if err != nil {
if _, err := util.PatchPVCStatus(pvc, newPVC, ctrl.kubeClient); err != nil {
klog.Errorf("Mark PVC %q as resize finished failed: %v", util.PVCKey(pvc), err)
return err
}
Expand All @@ -376,15 +411,14 @@ func (ctrl *resizeController) markPVCAsFSResizeRequired(pvc *v1.PersistentVolume
newPVC := pvc.DeepCopy()
newPVC.Status.Conditions = util.MergeResizeConditionsOfPVC(newPVC.Status.Conditions,
[]v1.PersistentVolumeClaimCondition{pvcCondition})
_, err := util.PatchPVCStatus(pvc, newPVC, ctrl.kubeClient)
if err != nil {

if _, err := util.PatchPVCStatus(pvc, newPVC, ctrl.kubeClient); err != nil {
klog.Errorf("Mark PVC %q as file system resize required failed: %v", util.PVCKey(pvc), err)
return err
}

klog.V(4).Infof("Mark PVC %q as file system resize required", util.PVCKey(pvc))
ctrl.eventRecorder.Eventf(pvc, v1.EventTypeNormal,
util.FileSystemResizeRequired, "Require file system resize of volume on node")

return err
return nil
}
Loading

0 comments on commit 2413e7d

Please sign in to comment.