-
Notifications
You must be signed in to change notification settings - Fork 167
fix: add applySas #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: add applySas #432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ type Service struct { | |
|
||
// ResourcesForSnap indicates all resources and scheduler configuration to be snapped. | ||
type ResourcesForSnap struct { | ||
Sas []corev1.ServiceAccount `json:"sas"` | ||
Pods []corev1.Pod `json:"pods"` | ||
Nodes []corev1.Node `json:"nodes"` | ||
Pvs []corev1.PersistentVolume `json:"pvs"` | ||
|
@@ -42,6 +43,7 @@ type ResourcesForSnap struct { | |
|
||
// ResourcesForLoad indicates all resources and scheduler configuration to be loaded. | ||
type ResourcesForLoad struct { | ||
Sas []v1.ServiceAccountApplyConfiguration `json:"sas"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I need to delete this line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saza-ku Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean we don't need the entire fix in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I mean we need to fix both oneshotimporter and syncer. And this has been achived by 8bab17c. So that's okay! And I mistakenly believed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we need additional fix. It needs to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saza-ku How can I fix it? Currently, all the changes in this PR can run normally on my local machine and meet my needs. Other fixes may require your guidance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done
LY-today marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Pods []v1.PodApplyConfiguration `json:"pods"` | ||
Nodes []v1.NodeApplyConfiguration `json:"nodes"` | ||
Pvs []v1.PersistentVolumeApplyConfiguration `json:"pvs"` | ||
|
@@ -103,7 +105,9 @@ func (s *Service) IgnoreSchedulerConfiguration() Option { | |
func (s *Service) get(ctx context.Context, opts options) (*ResourcesForSnap, error) { | ||
errgrp := util.NewErrGroupWithSemaphore(ctx) | ||
resources := ResourcesForSnap{} | ||
|
||
if err := s.listSas(ctx, &resources, errgrp, opts); err != nil { | ||
return nil, xerrors.Errorf("call listSas: %w", err) | ||
} | ||
if err := s.listPods(ctx, &resources, errgrp, opts); err != nil { | ||
return nil, xerrors.Errorf("call listPods: %w", err) | ||
} | ||
|
@@ -173,6 +177,9 @@ func (s *Service) apply(ctx context.Context, resources *ResourcesForLoad, opts o | |
if err := s.applyNodes(ctx, resources, errgrp, opts); err != nil { | ||
return xerrors.Errorf("call applyNodes: %w", err) | ||
} | ||
if err := s.applySas(ctx, resources, errgrp, opts); err != nil { | ||
return xerrors.Errorf("call applySas: %w", err) | ||
} | ||
if err := s.applyPods(ctx, resources, errgrp, opts); err != nil { | ||
return xerrors.Errorf("call applyPods: %w", err) | ||
} | ||
|
@@ -214,6 +221,24 @@ func (s *Service) Load(ctx context.Context, resources *ResourcesForLoad, opts .. | |
return nil | ||
} | ||
|
||
func (s *Service) listSas(ctx context.Context, r *ResourcesForSnap, eg *util.SemaphoredErrGroup, opts options) error { | ||
if err := eg.Go(func() error { | ||
sass, err := s.client.CoreV1().ServiceAccounts(metav1.NamespaceAll).List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
if !opts.ignoreErr { | ||
return xerrors.Errorf("call list Pod: %w", err) | ||
} | ||
klog.Errorf("failed to call list Pod: %v", err) | ||
sass = &corev1.ServiceAccountList{Items: []corev1.ServiceAccount{}} | ||
} | ||
r.Sas = sass.Items | ||
return nil | ||
}); err != nil { | ||
return xerrors.Errorf("start error group: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Service) listPods(ctx context.Context, r *ResourcesForSnap, eg *util.SemaphoredErrGroup, opts options) error { | ||
if err := eg.Go(func() error { | ||
pods, err := s.client.CoreV1().Pods(metav1.NamespaceAll).List(ctx, metav1.ListOptions{}) | ||
|
@@ -490,6 +515,31 @@ func (s *Service) applyNodes(ctx context.Context, r *ResourcesForLoad, eg *util. | |
return nil | ||
} | ||
|
||
func (s *Service) applySas(ctx context.Context, r *ResourcesForLoad, eg *util.SemaphoredErrGroup, opts options) error { | ||
for i := range r.Sas { | ||
sa := r.Sas[i] | ||
if err := eg.Go(func() error { | ||
sa.ObjectMetaApplyConfiguration.UID = nil | ||
sa.ObjectMetaApplyConfiguration.CreationTimestamp = nil | ||
sa.ObjectMetaApplyConfiguration.ResourceVersion = nil | ||
|
||
sa.WithAPIVersion("v1").WithKind("ServiceAccount") | ||
|
||
_, err := s.client.CoreV1().ServiceAccounts(*sa.Namespace).Apply(ctx, &sa, metav1.ApplyOptions{Force: true, FieldManager: "simulator"}) | ||
if err != nil { | ||
if !opts.ignoreErr { | ||
return xerrors.Errorf("apply Sa: %w", err) | ||
} | ||
klog.Errorf("failed to apply Sa: %v", err) | ||
} | ||
return nil | ||
}); err != nil { | ||
return xerrors.Errorf("start error group: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Service) applyPods(ctx context.Context, r *ResourcesForLoad, eg *util.SemaphoredErrGroup, opts options) error { | ||
for i := range r.Pods { | ||
pod := r.Pods[i] | ||
|
Uh oh!
There was an error while loading. Please reload this page.