Skip to content

Commit

Permalink
refact(k8s): K8s deps upgrade to v1.22.0, sig-storage-lib-external-pr…
Browse files Browse the repository at this point in the history
…ovisioner upgrade to v7.0.1 (#74)

* Vendoring files and go.mod changes
* pkg/ directory files method signature changes
* tests/ directory files method signature changes
* provisioner-localpv method signature changes, concurrency signal handling changes in start.go and signal-handler.go
* GitHub Actions and Dockerfile changes required to build with go v1.16.6

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih authored Aug 6, 2021
1 parent 38fdc67 commit f3d69d4
Show file tree
Hide file tree
Showing 2,523 changed files with 230,103 additions and 126,745 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ jobs:
if: ${{ (github.event.ref_type != 'tag') }}
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16.6

- name: Checkout
uses: actions/checkout@v2

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16.6

- name: Checkout
uses: actions/checkout@v2

Expand Down
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.
#
FROM golang:1.14.7 as build
FROM golang:1.16.6 as build

ARG BRANCH
ARG RELEASE_TAG
Expand Down
13 changes: 8 additions & 5 deletions cmd/provisioner-localpv/app/backward_compatability.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@ limitations under the License.
package app

import (
"context"

"github.com/pkg/errors"

blockdeviceclaim "github.com/openebs/maya/pkg/blockdeviceclaim/v1alpha1"

mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
klog "k8s.io/klog/v2"
)

// This function performs the preupgrade related tasks for 1.0 to 1.1
func performPreupgradeTasks(kubeClient *clientset.Clientset) error {
return addLocalPVFinalizerOnAssociatedBDCs(kubeClient)
func performPreupgradeTasks(ctx context.Context, kubeClient *clientset.Clientset) error {
return addLocalPVFinalizerOnAssociatedBDCs(ctx, kubeClient)
}

// Add localpv finalizer on the BDCs that are used by PVs provisioned from localpv provisioner
func addLocalPVFinalizerOnAssociatedBDCs(kubeClient *clientset.Clientset) error {
func addLocalPVFinalizerOnAssociatedBDCs(ctx context.Context, kubeClient *clientset.Clientset) error {
// Get the list of PVs that are provisioned by device based local pv provisioner
pvList, err := kubeClient.CoreV1().PersistentVolumes().List(
ctx,
metav1.ListOptions{
LabelSelector: string(mconfig.CASTypeKey) + "=local-device",
})
Expand All @@ -47,7 +50,7 @@ func addLocalPVFinalizerOnAssociatedBDCs(kubeClient *clientset.Clientset) error
bdcName := "bdc-" + pvObj.Name

bdcObj, err := blockdeviceclaim.NewKubeClient().WithNamespace(getOpenEBSNamespace()).
Get(bdcName, metav1.GetOptions{})
Get(ctx, bdcName, metav1.GetOptions{})
if err != nil {
// BDCs may not exist if the PV reclaimPolicy is set
// to 'Retain' and the BDCs have been manually removed
Expand Down
18 changes: 9 additions & 9 deletions cmd/provisioner-localpv/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ limitations under the License.
package app

import (
"context"
"strings"

mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
cast "github.com/openebs/maya/pkg/castemplate/v1alpha1"
hostpath "github.com/openebs/maya/pkg/hostpath/v1alpha1"
"github.com/openebs/maya/pkg/util"
"k8s.io/klog"
klog "k8s.io/klog/v2"

//"github.com/pkg/errors"
errors "github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
//storagev1 "k8s.io/api/storage/v1"
)
Expand Down Expand Up @@ -129,13 +129,13 @@ const (
// parsing and merging the configuration provided in the PVC
// annotation - cas.openebs.io/config with the
// default configuration of the provisioner.
func (p *Provisioner) GetVolumeConfig(pvName string, pvc *v1.PersistentVolumeClaim) (*VolumeConfig, error) {
func (p *Provisioner) GetVolumeConfig(ctx context.Context, pvName string, pvc *corev1.PersistentVolumeClaim) (*VolumeConfig, error) {

pvConfig := p.defaultConfig

//Fetch the SC
scName := GetStorageClassName(pvc)
sc, err := p.kubeClient.StorageV1().StorageClasses().Get(*scName, metav1.GetOptions{})
sc, err := p.kubeClient.StorageV1().StorageClasses().Get(ctx, *scName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "failed to get storageclass: missing sc name {%v}", scName)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func (c *VolumeConfig) getValue(key string) string {
}

// GetStorageClassName extracts the StorageClass name from PVC
func GetStorageClassName(pvc *v1.PersistentVolumeClaim) *string {
func GetStorageClassName(pvc *corev1.PersistentVolumeClaim) *string {
// Use beta annotation first
class, found := pvc.Annotations[betaStorageClassAnnotation]
if found {
Expand All @@ -294,7 +294,7 @@ func GetStorageClassName(pvc *v1.PersistentVolumeClaim) *string {
}

// GetLocalPVType extracts the Local PV Type from PV
func GetLocalPVType(pv *v1.PersistentVolume) string {
func GetLocalPVType(pv *corev1.PersistentVolume) string {
casType, found := pv.Labels[string(mconfig.CASTypeKey)]
if found {
return casType
Expand All @@ -305,7 +305,7 @@ func GetLocalPVType(pv *v1.PersistentVolume) string {
// GetNodeHostname extracts the Hostname from the labels on the Node
// If hostname label `kubernetes.io/hostname` is not present
// an empty string is returned.
func GetNodeHostname(n *v1.Node) string {
func GetNodeHostname(n *corev1.Node) string {
hostname, found := n.Labels[k8sNodeLabelKeyHostname]
if !found {
return ""
Expand All @@ -315,7 +315,7 @@ func GetNodeHostname(n *v1.Node) string {

// GetNodeLabelValue extracts the value from the given label on the Node
// If specificed label is not present an empty string is returned.
func GetNodeLabelValue(n *v1.Node, labelKey string) string {
func GetNodeLabelValue(n *corev1.Node, labelKey string) string {
labelValue, found := n.Labels[labelKey]
if !found {
return ""
Expand All @@ -325,7 +325,7 @@ func GetNodeLabelValue(n *v1.Node, labelKey string) string {

// GetTaints extracts the Taints from the Spec on the node
// If Taints are empty, it just returns empty structure of corev1.Taints
func GetTaints(n *v1.Node) []v1.Taint {
func GetTaints(n *corev1.Node) []corev1.Taint {
return n.Spec.Taints
}

Expand Down
30 changes: 16 additions & 14 deletions cmd/provisioner-localpv/app/helper_blockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
//"fmt"
//"path/filepath"
//"strings"
"context"
"time"

"k8s.io/klog"
klog "k8s.io/klog/v2"
//"github.com/pkg/errors"
errors "github.com/pkg/errors"

Expand All @@ -38,6 +39,7 @@ import (
blockdevice "github.com/openebs/maya/pkg/blockdevice/v1alpha2"
blockdeviceclaim "github.com/openebs/maya/pkg/blockdeviceclaim/v1alpha1"
corev1 "k8s.io/api/core/v1"

//ndmv1alpha1 "github.com/openebs/maya/pkg/apis/openebs.io/ndm/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -96,7 +98,7 @@ func (blkDevOpts *HelperBlockDeviceOptions) setBlockDeviceClaimFromPV(pv *corev1

// createBlockDeviceClaim creates a new BlockDeviceClaim for a given
// Local PV
func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOptions) error {
func (p *Provisioner) createBlockDeviceClaim(ctx context.Context, blkDevOpts *HelperBlockDeviceOptions) error {
klog.V(4).Infof("Creating Block Device Claim")
if err := blkDevOpts.validate(); err != nil {
return err
Expand All @@ -114,7 +116,7 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption
//creating a BDC, but BD was not yet available for 60+ seconds
_, err := blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Get(bdcName, metav1.GetOptions{})
Get(ctx, bdcName, metav1.GetOptions{})
if err == nil {
blkDevOpts.bdcName = bdcName
klog.Infof("Volume %v has been initialized with BDC:%v", blkDevOpts.name, bdcName)
Expand Down Expand Up @@ -143,7 +145,7 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption

_, err = blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Create(bdcObj.Object)
Create(ctx, bdcObj.Object)

if err != nil {
//TODO : Need to relook at this error
Expand All @@ -158,11 +160,11 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption

// getBlockDevicePath fetches the BDC associated with this Local PV
// or creates one. From the BDC, fetch the BD and get the path
func (p *Provisioner) getBlockDevicePath(blkDevOpts *HelperBlockDeviceOptions) (string, string, error) {
func (p *Provisioner) getBlockDevicePath(ctx context.Context, blkDevOpts *HelperBlockDeviceOptions) (string, string, error) {

klog.V(4).Infof("Getting Block Device Path")
if !blkDevOpts.hasBDC() {
err := p.createBlockDeviceClaim(blkDevOpts)
err := p.createBlockDeviceClaim(ctx, blkDevOpts)
if err != nil {
return "", "", err
}
Expand All @@ -176,7 +178,7 @@ func (p *Provisioner) getBlockDevicePath(blkDevOpts *HelperBlockDeviceOptions) (

bdc, err := blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Get(blkDevOpts.bdcName, metav1.GetOptions{})
Get(ctx, blkDevOpts.bdcName, metav1.GetOptions{})
if err != nil {
//TODO : Need to relook at this error
//If the error is about BDC being already present, then return nil
Expand All @@ -195,7 +197,7 @@ func (p *Provisioner) getBlockDevicePath(blkDevOpts *HelperBlockDeviceOptions) (
// if bdName not found should delete BDC and return err
if bdName == "" {
err := errors.Errorf("unable to find BD for BDC:%v associated with PV:%v and try to delete BDC", blkDevOpts.bdcName, blkDevOpts.name)
delErr := p.deleteBlockDeviceClaim(blkDevOpts)
delErr := p.deleteBlockDeviceClaim(ctx, blkDevOpts)
if delErr != nil {
return "", "", delErr
} else {
Expand Down Expand Up @@ -232,21 +234,21 @@ func (p *Provisioner) getBlockDevicePath(blkDevOpts *HelperBlockDeviceOptions) (

// deleteBlockDeviceClaim deletes the BlockDeviceClaim associated with the
// PV being deleted.
func (p *Provisioner) deleteBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOptions) error {
func (p *Provisioner) deleteBlockDeviceClaim(ctx context.Context, blkDevOpts *HelperBlockDeviceOptions) error {
klog.V(4).Infof("Delete Block Device Claim")
if !blkDevOpts.hasBDC() {
return nil
}

err := p.removeFinalizer(blkDevOpts)
err := p.removeFinalizer(ctx, blkDevOpts)
if err != nil {
// if finalizer is not removed, donot proceed with deletion
return errors.Errorf("unable to remove finalizer on BDC %v : %v", blkDevOpts.name, err)
}

err = blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Delete(blkDevOpts.bdcName, &metav1.DeleteOptions{})
Delete(ctx, blkDevOpts.bdcName, &metav1.DeleteOptions{})

if err != nil {
//TODO : Need to relook at this error
Expand All @@ -256,12 +258,12 @@ func (p *Provisioner) deleteBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption
}

//
func (p *Provisioner) removeFinalizer(blkDevOpts *HelperBlockDeviceOptions) error {
func (p *Provisioner) removeFinalizer(ctx context.Context, blkDevOpts *HelperBlockDeviceOptions) error {
klog.V(4).Info("removing local-pv finalizer on the BDC")

bdc, err := blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Get(blkDevOpts.bdcName, metav1.GetOptions{})
Get(ctx, blkDevOpts.bdcName, metav1.GetOptions{})
if err != nil {
return errors.Errorf("unable to get BDC %s for removing finalizer", blkDevOpts.bdcName)
}
Expand All @@ -272,7 +274,7 @@ func (p *Provisioner) removeFinalizer(blkDevOpts *HelperBlockDeviceOptions) erro
// udpate the BDC with the new finalizer array
_, err = blockdeviceclaim.NewKubeClient().
WithNamespace(p.namespace).
Update(bdc)
Update(ctx, bdc)

return err
}
25 changes: 13 additions & 12 deletions cmd/provisioner-localpv/app/helper_hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ and modified to work with the configuration options used by OpenEBS
package app

import (
"context"
"path/filepath"
"time"

errors "github.com/pkg/errors"
"k8s.io/klog"
klog "k8s.io/klog/v2"

hostpath "github.com/openebs/maya/pkg/hostpath/v1alpha1"

Expand Down Expand Up @@ -94,7 +95,7 @@ func (pOpts *HelperPodOptions) validate() error {
// createInitPod launches a helper(busybox) pod, to create the host path.
// The local pv expect the hostpath to be already present before mounting
// into pod. Validate that the local pv host path is not created under root.
func (p *Provisioner) createInitPod(pOpts *HelperPodOptions) error {
func (p *Provisioner) createInitPod(ctx context.Context, pOpts *HelperPodOptions) error {
var config podConfig
config.pOpts, config.podName = pOpts, "init"
//err := pOpts.validate()
Expand All @@ -116,12 +117,12 @@ func (p *Provisioner) createInitPod(pOpts *HelperPodOptions) error {
//Pass on the taints, to create tolerations.
config.taints = pOpts.selectedNodeTaints

iPod, err := p.launchPod(config)
iPod, err := p.launchPod(ctx, config)
if err != nil {
return err
}

if err := p.exitPod(iPod); err != nil {
if err := p.exitPod(ctx, iPod); err != nil {
return err
}

Expand All @@ -133,7 +134,7 @@ func (p *Provisioner) createInitPod(pOpts *HelperPodOptions) error {
// an unique PV path - under a given BasePath. From the absolute path,
// it extracts the base path and the PV path. The helper pod is then launched
// by mounting the base path - and performing a delete on the unique PV path.
func (p *Provisioner) createCleanupPod(pOpts *HelperPodOptions) error {
func (p *Provisioner) createCleanupPod(ctx context.Context, pOpts *HelperPodOptions) error {
var config podConfig
config.pOpts, config.podName = pOpts, "cleanup"
//err := pOpts.validate()
Expand All @@ -153,18 +154,18 @@ func (p *Provisioner) createCleanupPod(pOpts *HelperPodOptions) error {
return vErr
}

cPod, err := p.launchPod(config)
cPod, err := p.launchPod(ctx, config)
if err != nil {
return err
}

if err := p.exitPod(cPod); err != nil {
if err := p.exitPod(ctx, cPod); err != nil {
return err
}
return nil
}

func (p *Provisioner) launchPod(config podConfig) (*corev1.Pod, error) {
func (p *Provisioner) launchPod(ctx context.Context, config podConfig) (*corev1.Pod, error) {
// the helper pod need to be launched in privileged mode. This is because in CoreOS
// nodes, pods without privileged access cannot write to the host directory.
// Helper pods need to create and delete directories on the host.
Expand Down Expand Up @@ -206,13 +207,13 @@ func (p *Provisioner) launchPod(config podConfig) (*corev1.Pod, error) {
var hPod *corev1.Pod

//Launch the helper pod.
hPod, err = p.kubeClient.CoreV1().Pods(p.namespace).Create(helperPod)
hPod, err = p.kubeClient.CoreV1().Pods(p.namespace).Create(ctx, helperPod, metav1.CreateOptions{})
return hPod, err
}

func (p *Provisioner) exitPod(hPod *corev1.Pod) error {
func (p *Provisioner) exitPod(ctx context.Context, hPod *corev1.Pod) error {
defer func() {
e := p.kubeClient.CoreV1().Pods(p.namespace).Delete(hPod.Name, &metav1.DeleteOptions{})
e := p.kubeClient.CoreV1().Pods(p.namespace).Delete(ctx, hPod.Name, metav1.DeleteOptions{})
if e != nil {
klog.Errorf("unable to delete the helper pod: %v", e)
}
Expand All @@ -221,7 +222,7 @@ func (p *Provisioner) exitPod(hPod *corev1.Pod) error {
//Wait for the helper pod to complete it job and exit
completed := false
for i := 0; i < CmdTimeoutCounts; i++ {
checkPod, err := p.kubeClient.CoreV1().Pods(p.namespace).Get(hPod.Name, metav1.GetOptions{})
checkPod, err := p.kubeClient.CoreV1().Pods(p.namespace).Get(ctx, hPod.Name, metav1.GetOptions{})
if err != nil {
return err
} else if checkPod.Status.Phase == corev1.PodSucceeded {
Expand Down
Loading

0 comments on commit f3d69d4

Please sign in to comment.