Skip to content

Commit

Permalink
Merge pull request #118 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: fixed persistent volume cleanup & --address
  • Loading branch information
FabianKramm authored Aug 18, 2021
2 parents c808acf + 4f4f479 commit a942941
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions cmd/vclusterctl/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ConnectCmd struct {
UpdateCurrent bool
Print bool
LocalPort int
Address string

Server string

Expand Down Expand Up @@ -74,6 +75,7 @@ vcluster connect test --namespace test
cobraCmd.Flags().StringVar(&cmd.PodName, "pod", "", "The pod to connect to")
cobraCmd.Flags().StringVar(&cmd.Server, "server", "", "The server to connect to")
cobraCmd.Flags().IntVar(&cmd.LocalPort, "local-port", 8443, "The local port to forward the virtual cluster to")
cobraCmd.Flags().StringVar(&cmd.Address, "address", "", "The local address to start port forwarding under")
return cobraCmd
}

Expand Down Expand Up @@ -273,6 +275,9 @@ func (cmd *ConnectCmd) Connect(vclusterName string) error {
if cmd.Context != "" {
command = append(command, "--context", cmd.Context)
}
if cmd.Address != "" {
command = append(command, "--address", cmd.Address)
}

cmd.log.Infof("Starting port forwarding: %s", strings.Join(command, " "))
portforwardCmd := exec.Command(command[0], command[1:]...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/garbagecollect/garbagecollect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Source struct {

func NewGarbageCollectSource(collector GarbageCollect, stopChan <-chan struct{}, log loghelper.Logger) *Source {
return &Source{
Period: time.Minute,
Period: time.Second * 30,

log: log,
run: collector,
Expand Down
31 changes: 16 additions & 15 deletions pkg/controllers/resources/persistentvolumes/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@ func (s *syncer) NewList() client.ObjectList {
}

func (s *syncer) ForwardCreateNeeded(vObj client.Object) (bool, error) {
vPersistentVolume := vObj.(*corev1.PersistentVolume)
if vPersistentVolume.Annotations != nil || vPersistentVolume.Annotations[HostClusterPersistentVolumeAnnotation] != "" {
return false, nil
}

return true, nil
}

func (s *syncer) ForwardCreate(ctx context.Context, vObj client.Object, log loghelper.Logger) (ctrl.Result, error) {
vPv := vObj.(*corev1.PersistentVolume)
if vPv.DeletionTimestamp != nil {
if vPv.DeletionTimestamp != nil || (vPv.Annotations != nil && vPv.Annotations[HostClusterPersistentVolumeAnnotation] != "") {
if len(vPv.Finalizers) > 0 {
// delete the finalizer here so that the object can be deleted
vPv.Finalizers = []string{}
log.Infof("remove virtual persistent volume %s finalizers, because object should get deleted", vPv.Name)
return ctrl.Result{}, s.virtualClient.Update(ctx, vPv)
}

// delete the finalizer here so that the object can be deleted
vPv.Finalizers = []string{}
log.Infof("remove virtual persistent volume %s finalizers, because object should get deleted", vPv.Name)
return ctrl.Result{}, s.virtualClient.Update(ctx, vPv)
log.Infof("remove virtual persistent volume %s, because object should get deleted", vPv.Name)
return ctrl.Result{}, s.virtualClient.Delete(ctx, vPv)
}

pPv, err := s.translatePV(vPv)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -98,7 +99,7 @@ func (s *syncer) ForwardCreate(ctx context.Context, vObj client.Object, log logh
func (s *syncer) ForwardUpdate(ctx context.Context, pObj client.Object, vObj client.Object, log loghelper.Logger) (ctrl.Result, error) {
pPersistentVolume := pObj.(*corev1.PersistentVolume)
vPersistentVolume := vObj.(*corev1.PersistentVolume)
if vPersistentVolume.Annotations != nil || vPersistentVolume.Annotations[HostClusterPersistentVolumeAnnotation] != "" {
if vPersistentVolume.Annotations != nil && vPersistentVolume.Annotations[HostClusterPersistentVolumeAnnotation] != "" {
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -135,7 +136,7 @@ func (s *syncer) ForwardUpdate(ctx context.Context, pObj client.Object, vObj cli
func (s *syncer) ForwardUpdateNeeded(pObj client.Object, vObj client.Object) (bool, error) {
pPersistentVolume := pObj.(*corev1.PersistentVolume)
vPersistentVolume := vObj.(*corev1.PersistentVolume)
if vPersistentVolume.Annotations != nil || vPersistentVolume.Annotations[HostClusterPersistentVolumeAnnotation] != "" {
if vPersistentVolume.Annotations != nil && vPersistentVolume.Annotations[HostClusterPersistentVolumeAnnotation] != "" {
return false, nil
}

Expand Down Expand Up @@ -167,7 +168,7 @@ func (s *syncer) BackwardUpdate(ctx context.Context, pObj client.Object, vObj cl
if err != nil {
return ctrl.Result{}, err
}

vPersistentVolume = updatedObj
}

Expand All @@ -179,7 +180,7 @@ func (s *syncer) BackwardUpdate(ctx context.Context, pObj client.Object, vObj cl
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -367,7 +368,7 @@ func (s *syncer) calcPVDiffBackward(vPv *corev1.PersistentVolume, pPv *corev1.Pe
translatedSpec.ClaimRef.Name = vPvc.Name
translatedSpec.ClaimRef.Namespace = vPvc.Namespace
}

// check storage class
if translate.IsManagedCluster(s.targetNamespace, pPv) == false {
if equality.Semantic.DeepEqual(vPv.Spec.StorageClassName, translatedSpec.StorageClassName) == false {
Expand Down

0 comments on commit a942941

Please sign in to comment.