forked from longhorn/longhorn-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Longhorn related PV/PVC annnotations for new CSI provisioner
1. The new external CSI provisioner will use driver name as its provisioner name. Previously, the provisioner name is different from driver name, which is `rancher.io/longhorn` and does not follow the driver naming schema. Hence we cannot deploy a compatible provisioner and a related CSI driver with old provisioner name to handle the existing volumes. 2. The external CSI provisioner uses the annotations of PVC/PV to find the matching CSI driver. Hence we can updating the annotations for Longhorn related PVC/PV so that the new provisioner is able to verify and handle the existing volumes. Longhorn longhorn#347 Signed-off-by: Shuo Wu <shuo@rancher.com>
- Loading branch information
Shuo Wu
committed
Nov 5, 2019
1 parent
93ae2ab
commit 4462d48
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clientset "k8s.io/client-go/kubernetes" | ||
|
||
"github.com/longhorn/longhorn-manager/types" | ||
) | ||
|
||
const ( | ||
PVCAnnotationCSIProvisioner = "volume.beta.kubernetes.io/storage-provisioner" | ||
PVAnnotationCSIProvisioner = "pv.kubernetes.io/provisioned-by" | ||
) | ||
|
||
func upgradeLonghornRelatedComponents(kubeClient *clientset.Clientset, namespace string) error { | ||
logrus.Infof("Upgrading Longhorn related components for CSI v1.1.0") | ||
|
||
pvList, err := kubeClient.CoreV1().PersistentVolumes().List(metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
for _, pv := range pvList.Items { | ||
if v, exist := pv.Annotations[PVAnnotationCSIProvisioner]; exist { | ||
if v == types.DeprecatedProvisionerName { | ||
pv.Annotations[PVAnnotationCSIProvisioner] = types.LonghornDriverName | ||
_, err := kubeClient.CoreV1().PersistentVolumes().Update(&pv) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
pvc, err := kubeClient.CoreV1().PersistentVolumeClaims(pv.Spec.ClaimRef.Namespace).Get(pv.Spec.ClaimRef.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
if v, exist := pvc.Annotations[PVCAnnotationCSIProvisioner]; exist && v == types.DeprecatedProvisionerName { | ||
pvc.Annotations[PVCAnnotationCSIProvisioner] = types.LonghornDriverName | ||
_, err := kubeClient.CoreV1().PersistentVolumeClaims(pvc.Namespace).Update(pvc) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters