Skip to content

Commit

Permalink
Switched to k8s 1.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
petermicuch committed Dec 10, 2020
1 parent 920c708 commit a706bed
Show file tree
Hide file tree
Showing 3 changed files with 551 additions and 230 deletions.
23 changes: 12 additions & 11 deletions cmd/nfs-subdir-external-provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"errors"
"flag"
"fmt"
Expand All @@ -31,12 +32,11 @@ import (

storage "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/sig-storage-lib-external-provisioner/controller"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v6/controller"
)

const (
Expand Down Expand Up @@ -78,9 +78,9 @@ const (

var _ controller.Provisioner = &nfsProvisioner{}

func (p *nfsProvisioner) Provision(options controller.ProvisionOptions) (*v1.PersistentVolume, error) {
func (p *nfsProvisioner) Provision(ctx context.Context, options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
if options.PVC.Spec.Selector != nil {
return nil, fmt.Errorf("claim Selector is not supported")
return nil, controller.ProvisioningFinished, fmt.Errorf("claim Selector is not supported")
}
glog.V(4).Infof("nfs provisioner: VolumeOptions %v", options)

Expand Down Expand Up @@ -110,7 +110,7 @@ func (p *nfsProvisioner) Provision(options controller.ProvisionOptions) (*v1.Per

glog.V(4).Infof("creating path %s", fullPath)
if err := os.MkdirAll(fullPath, 0777); err != nil {
return nil, errors.New("unable to create directory to provision new pv: " + err.Error())
return nil, controller.ProvisioningFinished, errors.New("unable to create directory to provision new pv: " + err.Error())
}
os.Chmod(fullPath, 0777)

Expand All @@ -134,10 +134,10 @@ func (p *nfsProvisioner) Provision(options controller.ProvisionOptions) (*v1.Per
},
},
}
return pv, nil
return pv, controller.ProvisioningFinished, nil
}

func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
func (p *nfsProvisioner) Delete(ctx context.Context,volume *v1.PersistentVolume) error {
path := volume.Spec.PersistentVolumeSource.NFS.Path
relativePath := strings.Replace(path, p.path, "", 1)
oldPath := filepath.Join(mountPath, relativePath)
Expand All @@ -147,7 +147,7 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
return nil
}
// Get the storage class for this volume.
storageClass, err := p.getClassForVolume(volume)
storageClass, err := p.getClassForVolume(ctx, volume)
if err != nil {
return err
}
Expand Down Expand Up @@ -185,15 +185,15 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
}

// getClassForVolume returns StorageClass
func (p *nfsProvisioner) getClassForVolume(pv *v1.PersistentVolume) (*storage.StorageClass, error) {
func (p *nfsProvisioner) getClassForVolume(context context.Context, pv *v1.PersistentVolume) (*storage.StorageClass, error) {
if p.client == nil {
return nil, fmt.Errorf("Cannot get kube client")
}
className := helper.GetPersistentVolumeClass(pv)
if className == "" {
return nil, fmt.Errorf("Volume has no storage class")
}
class, err := p.client.StorageV1().StorageClasses().Get(className, metav1.GetOptions{})
class, err := p.client.StorageV1().StorageClasses().Get(context, className, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -269,5 +269,6 @@ func main() {
serverVersion.GitVersion,
controller.LeaderElection(leaderElection),
)
pc.Run(wait.NeverStop)
// Never stops.
pc.Run(context.Background())
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ require (
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
k8s.io/klog v1.0.0 // indirect
k8s.io/kubernetes v1.15.0
k8s.io/kubernetes v1.18.0
k8s.io/utils v0.0.0-20200327001022-6496210b90e8 // indirect
sigs.k8s.io/sig-storage-lib-external-provisioner v4.1.0+incompatible
sigs.k8s.io/sig-storage-lib-external-provisioner/v6 v6.0.0
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190620085554-14e95df34f1f
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190620085212-47dc9a115b18
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190620085706-2090e6d8f84c
k8s.io/client-go => k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190620090043-8301c0bda1f0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20190620090013-c9a0fc045dc1
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b
k8s.io/component-base => k8s.io/component-base v0.0.0-20190620085130-185d68e6e6ea
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190531030430-6117653b35f1
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20190620090116-299a7b270edc
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190620085325-f29e2b4a4f84
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20190620085942-b7f18460b210
k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20190620085809-589f994ddf7f
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20190620085912-4acac5405ec6
k8s.io/kubelet => k8s.io/kubelet v0.0.0-20190620085838-f1cb295a73c9
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20190620090156-2138f2c9de18
k8s.io/metrics => k8s.io/metrics v0.0.0-20190620085625-3b22d835f165
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20190620085408-1aef9010884e
k8s.io/api => k8s.io/api v0.18.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.0
k8s.io/apimachinery => k8s.io/apimachinery v0.18.2-beta.0
k8s.io/apiserver => k8s.io/apiserver v0.18.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.18.0
k8s.io/client-go => k8s.io/client-go v0.18.0
k8s.io/cloud-provider => k8s.io/cloud-provider v0.18.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.18.0
k8s.io/code-generator => k8s.io/code-generator v0.18.3-beta.0
k8s.io/component-base => k8s.io/component-base v0.18.0
k8s.io/cri-api => k8s.io/cri-api v0.18.11-rc.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.18.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.18.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.18.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.18.0
k8s.io/kubectl => k8s.io/kubectl v0.18.0
k8s.io/kubelet => k8s.io/kubelet v0.18.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.18.0
k8s.io/metrics => k8s.io/metrics v0.18.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.18.0
)
Loading

0 comments on commit a706bed

Please sign in to comment.