Skip to content

Commit

Permalink
feature: adapt projected volume in any version
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu <[email protected]>
  • Loading branch information
renxiangyu committed Jan 2, 2024
1 parent 04938bf commit 82b2444
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 173 deletions.
18 changes: 12 additions & 6 deletions pkg/clustertree/cluster-manager/controllers/common_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,20 @@ func (r *SyncResourcesReconciler) SyncResource(ctx context.Context, request reco
klog.V(4).Infof("Started sync resource processing, ns: %s, name: %s", request.Namespace, request.Name)

deleteSecretInClient := false
resourceNamespace := request.Namespace
masterResourceName := request.Name
memberResourceName := masterResourceName
if r.GroupVersionResource == utils.GVR_CONFIGMAP && masterResourceName == utils.RooTCAConfigMapName {
memberResourceName = utils.MasterRooTCAName
}

obj, err := r.DynamicRootClient.Resource(r.GroupVersionResource).Namespace(request.Namespace).Get(ctx, request.Name, metav1.GetOptions{})
obj, err := r.DynamicRootClient.Resource(r.GroupVersionResource).Namespace(resourceNamespace).Get(ctx, masterResourceName, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
return err
}
// get obj in leaf cluster
_, err := lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(request.Namespace).Get(ctx, request.Name, metav1.GetOptions{})
_, err := lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(resourceNamespace).Get(ctx, memberResourceName, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
klog.Errorf("Get %s from leaef cluster failed, error: %v", obj.GetKind(), err)
Expand All @@ -140,17 +146,17 @@ func (r *SyncResourcesReconciler) SyncResource(ctx context.Context, request reco

if deleteSecretInClient || obj.GetDeletionTimestamp() != nil {
// delete OBJ in leaf cluster
if err = lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(request.Namespace).Delete(ctx, request.Name, metav1.DeleteOptions{}); err != nil {
if err = lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(resourceNamespace).Delete(ctx, memberResourceName, metav1.DeleteOptions{}); err != nil {
if errors.IsNotFound(err) {
return nil
}
return err
}
klog.V(4).Infof("%s %q deleted", r.GroupVersionResource.Resource, request.Name)
klog.V(4).Infof("%s %q deleted in member cluster", r.GroupVersionResource.Resource, memberResourceName)
return nil
}

old, err := lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(request.Namespace).Get(ctx, request.Name, metav1.GetOptions{})
old, err := lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(resourceNamespace).Get(ctx, memberResourceName, metav1.GetOptions{})

if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -177,7 +183,7 @@ func (r *SyncResourcesReconciler) SyncResource(ctx context.Context, request reco
if !utils.IsObjectUnstructuredGlobal(old.GetAnnotations()) {
return nil
}
_, err = lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(request.Namespace).Update(ctx, latest, metav1.UpdateOptions{})
_, err = lr.DynamicClient.Resource(r.GroupVersionResource).Namespace(resourceNamespace).Update(ctx, latest, metav1.UpdateOptions{})
if err != nil {
klog.Errorf("update %s from client cluster failed, error: %v", latest.GetKind(), err)
return err
Expand Down
Loading

0 comments on commit 82b2444

Please sign in to comment.