Skip to content

Commit

Permalink
Merge pull request #225 from jsafrane/bump-provisioner-lib-2.2.0
Browse files Browse the repository at this point in the history
Bump provisioner lib to 2.2.0 + use klog
  • Loading branch information
k8s-ci-robot authored Feb 7, 2019
2 parents 19b7dc3 + fc06a57 commit 3c0c827
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 1,604 deletions.
16 changes: 4 additions & 12 deletions Gopkg.lock

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

6 changes: 1 addition & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@
name = "github.com/kubernetes-csi/csi-test"
version = "v1.0.0-1"

[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/kubernetes-csi/external-snapshotter"
version = "1.0.0-rc4"

[[constraint]]
name = "github.com/kubernetes-sigs/sig-storage-lib-external-provisioner"
version = "v2.0.0"
version = "v2.2.0"

[[constraint]]
name = "google.golang.org/grpc"
Expand Down
30 changes: 16 additions & 14 deletions cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
"strings"
"time"

"github.com/golang/glog"
"k8s.io/klog"

flag "github.com/spf13/pflag"
"google.golang.org/grpc"

Expand Down Expand Up @@ -65,57 +66,58 @@ func init() {
flag.Var(utilflag.NewMapStringBool(&featureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

klog.InitFlags(nil)
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
flag.Parse()
flag.Set("logtostderr", "true")
flag.Parse()

if err := utilfeature.DefaultFeatureGate.SetFromMap(featureGates); err != nil {
glog.Fatal(err)
klog.Fatal(err)
}

if *showVersion {
fmt.Println(os.Args[0], version)
os.Exit(0)
}
glog.Infof("Version: %s", version)
klog.Infof("Version: %s", version)

// get the KUBECONFIG from env if specified (useful for local/debug cluster)
kubeconfigEnv := os.Getenv("KUBECONFIG")

if kubeconfigEnv != "" {
glog.Infof("Found KUBECONFIG environment variable set, using that..")
klog.Infof("Found KUBECONFIG environment variable set, using that..")
kubeconfig = &kubeconfigEnv
}

if *master != "" || *kubeconfig != "" {
glog.Infof("Either master or kubeconfig specified. building kube config from that..")
klog.Infof("Either master or kubeconfig specified. building kube config from that..")
config, err = clientcmd.BuildConfigFromFlags(*master, *kubeconfig)
} else {
glog.Infof("Building kube configs for running in cluster...")
klog.Infof("Building kube configs for running in cluster...")
config, err = rest.InClusterConfig()
}
if err != nil {
glog.Fatalf("Failed to create config: %v", err)
klog.Fatalf("Failed to create config: %v", err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatalf("Failed to create client: %v", err)
klog.Fatalf("Failed to create client: %v", err)
}
// snapclientset.NewForConfig creates a new Clientset for VolumesnapshotV1alpha1Client
snapClient, err := snapclientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Failed to create snapshot client: %v", err)
klog.Fatalf("Failed to create snapshot client: %v", err)
}
csiAPIClient, err := csiclientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Failed to create CSI API client: %v", err)
klog.Fatalf("Failed to create CSI API client: %v", err)
}

// The controller needs to know what the server version is because out-of-tree
// provisioners aren't officially supported until 1.5
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
glog.Fatalf("Error getting server version: %v", err)
klog.Fatalf("Error getting server version: %v", err)
}

// Provisioner will stay in Init until driver opens csi socket, once it's done
Expand All @@ -134,9 +136,9 @@ func init() {
// Autodetect provisioner name
provisionerName, err := ctrl.GetDriverName(grpcClient, *connectionTimeout)
if err != nil {
glog.Fatalf("Error getting CSI driver name: %s", err)
klog.Fatalf("Error getting CSI driver name: %s", err)
}
glog.V(2).Infof("Detected CSI driver %s", provisionerName)
klog.V(2).Infof("Detected CSI driver %s", provisionerName)

// Generate a unique ID for this provisioner
timeStamp := time.Now().UnixNano() / int64(time.Millisecond)
Expand Down
43 changes: 21 additions & 22 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
_ "k8s.io/apimachinery/pkg/util/json"

"github.com/golang/glog"
"k8s.io/klog"

"github.com/kubernetes-sigs/sig-storage-lib-external-provisioner/controller"
"github.com/kubernetes-sigs/sig-storage-lib-external-provisioner/util"
Expand Down Expand Up @@ -181,16 +180,16 @@ var (
// from external-attacher/pkg/connection
//TODO consolidate ane librarize
func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
glog.V(5).Infof("GRPC call: %s", method)
glog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
klog.V(5).Infof("GRPC call: %s", method)
klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
err := invoker(ctx, method, req, reply, cc, opts...)
glog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
glog.V(5).Infof("GRPC error: %v", err)
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
klog.V(5).Infof("GRPC error: %v", err)
return err
}

func Connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
glog.V(2).Infof("Connecting to %s", address)
klog.V(2).Infof("Connecting to %s", address)
dialOptions := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithBackoffMaxDelay(time.Second),
Expand All @@ -210,14 +209,14 @@ func Connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
defer cancel()
for {
if !conn.WaitForStateChange(ctx, conn.GetState()) {
glog.V(4).Infof("Connection timed out")
klog.V(4).Infof("Connection timed out")
return conn, fmt.Errorf("Connection timed out")
}
if conn.GetState() == connectivity.Ready {
glog.V(3).Infof("Connected")
klog.V(3).Infof("Connected")
return conn, nil
}
glog.V(4).Infof("Still trying, connection is %s", conn.GetState())
klog.V(4).Infof("Still trying, connection is %s", conn.GetState())
}
}

Expand Down Expand Up @@ -477,7 +476,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
if strings.ToLower(k) == "fstype" {
fsType = v
fsTypesFound++
glog.Warningf(deprecationWarning("fstype", prefixedFsTypeKey, ""))
klog.Warningf(deprecationWarning("fstype", prefixedFsTypeKey, ""))
} else if k == prefixedFsTypeKey {
fsType = v
fsTypesFound++
Expand Down Expand Up @@ -532,7 +531,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
req.AccessibilityRequirements = requirements
}

glog.V(5).Infof("CreateVolumeRequest %+v", req)
klog.V(5).Infof("CreateVolumeRequest %+v", req)

rep := &csi.CreateVolumeResponse{}

Expand Down Expand Up @@ -580,7 +579,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
if status, ok := status.FromError(err); ok {
if status.Code() == codes.DeadlineExceeded {
// CreateVolume timed out, give it another chance to complete
glog.Warningf("CreateVolume timeout: %s has expired, operation will be retried", p.timeout.String())
klog.Warningf("CreateVolume timeout: %s has expired, operation will be retried", p.timeout.String())
return false, nil
}
}
Expand All @@ -593,7 +592,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
}

if rep.Volume != nil {
glog.V(3).Infof("create volume rep: %+v", *rep.Volume)
klog.V(3).Infof("create volume rep: %+v", *rep.Volume)
}
volumeAttributes := map[string]string{provisionerIDKey: p.identity}
for k, v := range rep.Volume.VolumeContext {
Expand Down Expand Up @@ -654,7 +653,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
pv.Spec.PersistentVolumeSource.CSI.FSType = fsType
}

glog.Infof("successfully created PV %+v", pv.Spec.PersistentVolumeSource)
klog.Infof("successfully created PV %+v", pv.Spec.PersistentVolumeSource)

return pv, nil
}
Expand Down Expand Up @@ -698,13 +697,13 @@ func (p *csiProvisioner) getVolumeContentSource(options controller.VolumeOptions
if snapshotObj.ObjectMeta.DeletionTimestamp != nil {
return nil, fmt.Errorf("snapshot %s is currently being deleted", options.PVC.Spec.DataSource.Name)
}
glog.V(5).Infof("VolumeSnapshot %+v", snapshotObj)
klog.V(5).Infof("VolumeSnapshot %+v", snapshotObj)

snapContentObj, err := p.snapshotClient.VolumesnapshotV1alpha1().VolumeSnapshotContents().Get(snapshotObj.Spec.SnapshotContentName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error getting snapshot:snapshotcontent %s:%s from api server: %v", snapshotObj.Name, snapshotObj.Spec.SnapshotContentName, err)
}
glog.V(5).Infof("VolumeSnapshotContent %+v", snapContentObj)
klog.V(5).Infof("VolumeSnapshotContent %+v", snapContentObj)

if snapContentObj.Spec.VolumeSnapshotSource.CSI == nil {
return nil, fmt.Errorf("error getting snapshot source from snapshot:snapshotcontent %s:%s", snapshotObj.Name, snapshotObj.Spec.SnapshotContentName)
Expand All @@ -715,22 +714,22 @@ func (p *csiProvisioner) getVolumeContentSource(options controller.VolumeOptions
SnapshotId: snapContentObj.Spec.VolumeSnapshotSource.CSI.SnapshotHandle,
},
}
glog.V(5).Infof("VolumeContentSource_Snapshot %+v", snapshotSource)
klog.V(5).Infof("VolumeContentSource_Snapshot %+v", snapshotSource)

if snapshotObj.Status.RestoreSize != nil {
capacity, exists := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
if !exists {
return nil, fmt.Errorf("error getting capacity for PVC %s when creating snapshot %s", options.PVC.Name, snapshotObj.Name)
}
volSizeBytes := capacity.Value()
glog.V(5).Infof("Requested volume size is %d and snapshot size is %d for the source snapshot %s", int64(volSizeBytes), int64(snapshotObj.Status.RestoreSize.Value()), snapshotObj.Name)
klog.V(5).Infof("Requested volume size is %d and snapshot size is %d for the source snapshot %s", int64(volSizeBytes), int64(snapshotObj.Status.RestoreSize.Value()), snapshotObj.Name)
// When restoring volume from a snapshot, the volume size should
// be equal to or larger than its snapshot size.
if int64(volSizeBytes) < int64(snapshotObj.Status.RestoreSize.Value()) {
return nil, fmt.Errorf("requested volume size %d is less than the size %d for the source snapshot %s", int64(volSizeBytes), int64(snapshotObj.Status.RestoreSize.Value()), snapshotObj.Name)
}
if int64(volSizeBytes) > int64(snapshotObj.Status.RestoreSize.Value()) {
glog.Warningf("requested volume size %d is greater than the size %d for the source snapshot %s. Volume plugin needs to handle volume expansion.", int64(volSizeBytes), int64(snapshotObj.Status.RestoreSize.Value()), snapshotObj.Name)
klog.Warningf("requested volume size %d is greater than the size %d for the source snapshot %s. Volume plugin needs to handle volume expansion.", int64(volSizeBytes), int64(snapshotObj.Status.RestoreSize.Value()), snapshotObj.Name)
}
}

Expand Down Expand Up @@ -807,12 +806,12 @@ func verifyAndGetSecretNameAndNamespaceTemplate(secret deprecatedSecretParamsMap
if t, ok := storageClassParams[secret.deprecatedSecretNameKey]; ok {
nameTemplate = t
numName++
glog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, ""))
klog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, ""))
}
if t, ok := storageClassParams[secret.deprecatedSecretNamespaceKey]; ok {
namespaceTemplate = t
numNamespace++
glog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, ""))
klog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, ""))
}
if t, ok := storageClassParams[secret.secretNameKey]; ok {
nameTemplate = t
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"strings"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
csiv1alpha1 "k8s.io/csi-api/pkg/apis/csi/v1alpha1"
csiclientset "k8s.io/csi-api/pkg/client/clientset/versioned"
"k8s.io/klog"
)

// topologyTerm represents a single term where its topology key value pairs are AND'd together.
Expand Down Expand Up @@ -148,7 +148,7 @@ func aggregateTopologies(
nodeInfos, err := csiAPIClient.CsiV1alpha1().CSINodeInfos().List(metav1.ListOptions{})
if err != nil {
// We must support provisioning if CSINodeInfo is missing, for backward compatibility.
glog.Warningf("error listing CSINodeInfos: %v; proceeding to provision without topology information", err)
klog.Warningf("error listing CSINodeInfos: %v; proceeding to provision without topology information", err)
return nil, nil
}

Expand All @@ -168,7 +168,7 @@ func aggregateTopologies(
selectedNodeInfo, err := csiAPIClient.CsiV1alpha1().CSINodeInfos().Get(selectedNode.Name, metav1.GetOptions{})
if err != nil {
// We must support provisioning if CSINodeInfo is missing, for backward compatibility.
glog.Warningf("error getting CSINodeInfo for selected node %q: %v; proceeding to provision without topology information", selectedNode.Name, err)
klog.Warningf("error getting CSINodeInfo for selected node %q: %v; proceeding to provision without topology information", selectedNode.Name, err)
return nil, nil
}
topologyKeys = getTopologyKeys(selectedNodeInfo, driverName)
Expand Down
Loading

0 comments on commit 3c0c827

Please sign in to comment.