Skip to content
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

Deprecate PodDecoration spec.injectStrategy.group #165

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions apis/apps/v1alpha1/poddecoration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,6 @@ type PodDecorationUpdateStrategy struct {
RollingUpdate *PodDecorationRollingUpdate `json:"rollingUpdate,omitempty"`
}

type PodDecorationInjectStrategy struct {
// Group provides the name of the group this PodDecoration belongs to.
// Only one PodDecoration is active when multiple PodDecorations share the same group value.
Group string `json:"group,omitempty"`
// Weight indicates the priority to apply for a group of PodDecorations with same group value.
// The greater one has higher priority to apply.
// Default value is 0.
Weight *int32 `json:"weight,omitempty"`
}

type PodDecorationRollingUpdate struct {
// Partition controls the update progress by indicating how many pods should be updated.
// Partition value indicates the number of Pods which should be updated to the updated revision.
Expand Down Expand Up @@ -187,8 +177,10 @@ type PodDecorationSpec struct {
// UpdateStrategy carries the strategy configuration for update.
UpdateStrategy PodDecorationUpdateStrategy `json:"updateStrategy,omitempty"`

// InjectStrategy carries the strategy configuration for injection
InjectStrategy PodDecorationInjectStrategy `json:"injectStrategy,omitempty"`
// Weight indicates the priority to apply for a group of PodDecorations with same group value.
// The greater one has higher priority to apply.
// Default value is 0.
Weight *int32 `json:"weight,omitempty"`

// Template includes the decoration message about pod template.
Template PodDecorationPodTemplate `json:"template,omitempty"`
Expand Down
26 changes: 5 additions & 21 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 6 additions & 16 deletions config/crd/bases/apps.kusionstack.io_poddecorations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,6 @@ spec:
defaults to 20
format: int32
type: integer
injectStrategy:
description: InjectStrategy carries the strategy configuration for
injection
properties:
group:
description: Group provides the name of the group this PodDecoration
belongs to. Only one PodDecoration is active when multiple PodDecorations
share the same group value.
type: string
weight:
description: Weight indicates the priority to apply for a group
of PodDecorations with same group value. The greater one has
higher priority to apply. Default value is 0.
format: int32
type: integer
type: object
selector:
description: Selector is a label query over pods that should be injected
with PodDecoration
Expand Down Expand Up @@ -5394,6 +5378,12 @@ spec:
x-kubernetes-map-type: atomic
type: object
type: object
weight:
description: Weight indicates the priority to apply for a group of
PodDecorations with same group value. The greater one has higher
priority to apply. Default value is 0.
format: int32
type: integer
type: object
status:
description: PodDecorationStatus defines the observed state of PodDecoration
Expand Down
23 changes: 2 additions & 21 deletions pkg/controllers/collaset/utils/poddecoration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type PodDecorationGetter interface {
GetDecorationByRevisions(ctx context.Context, revisions ...string) (map[string]*appsv1alpha1.PodDecoration, error)
GetLatestDecorationsByTargetLabel(ctx context.Context, labels map[string]string) (map[string]*appsv1alpha1.PodDecoration, error)
GetUpdatedDecorationsByOldPod(ctx context.Context, pod *corev1.Pod) (map[string]*appsv1alpha1.PodDecoration, error)
GetUpdatedDecorationsByOldRevisions(ctx context.Context, labels map[string]string, oldPDRevisions map[string]string) (map[string]*appsv1alpha1.PodDecoration, error)
}

func NewPodDecorationGetter(ctx context.Context, c client.Client, namespace string) (PodDecorationGetter, error) {
Expand Down Expand Up @@ -102,22 +101,17 @@ func (p *podDecorationGetter) GetUpdatedDecorationsByOldPod(ctx context.Context,
for _, info := range infos {
oldRevisions[info.Name] = info.Revision
}
return p.GetUpdatedDecorationsByOldRevisions(ctx, pod.Labels, oldRevisions)
return p.getUpdatedDecorationsByOldRevisions(ctx, pod.Labels, oldRevisions)
}

func (p *podDecorationGetter) GetUpdatedDecorationsByOldRevisions(ctx context.Context, labels map[string]string, oldPDRevisions map[string]string) (map[string]*appsv1alpha1.PodDecoration, error) {
func (p *podDecorationGetter) getUpdatedDecorationsByOldRevisions(ctx context.Context, labels map[string]string, oldPDRevisions map[string]string) (map[string]*appsv1alpha1.PodDecoration, error) {
updatedRevisions, _ := utilspoddecoration.GetEffectiveRevisionsFormLatestDecorations(p.latestPodDecorations, labels)
// key: Group name, value: PodDecoration name
effectiveGroup := map[string]string{}
updatedPDs, err := p.GetDecorationByRevisions(ctx, updatedRevisions.List()...)
if err != nil {
return nil, err
}
// delete updated PodDecorations in old revisions
for _, pd := range updatedPDs {
if pd.Spec.InjectStrategy.Group != "" {
effectiveGroup[pd.Spec.InjectStrategy.Group] = pd.Name
}
delete(oldPDRevisions, pd.Name)
}

Expand All @@ -131,19 +125,6 @@ func (p *podDecorationGetter) GetUpdatedDecorationsByOldRevisions(ctx context.Co
if err != nil {
return nil, err
}
// delete updated group in old stable PodDecorations
var shouldDeleteRevisions []string
for rev, pd := range oldStablePDs {
group := pd.Spec.InjectStrategy.Group
if group != "" {
if _, ok := effectiveGroup[group]; ok {
shouldDeleteRevisions = append(shouldDeleteRevisions, rev)
}
}
}
for _, rev := range shouldDeleteRevisions {
delete(oldStablePDs, rev)
}

for rev, pd := range oldStablePDs {
if p.latestPodDecorationNames.Has(pd.Name) {
Expand Down
Loading
Loading