Skip to content
Closed
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
10 changes: 5 additions & 5 deletions pkg/controller/sandbox/core/common_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type commonControl struct {
rateLimiter *RateLimiter
}

func NewCommonControl(c client.Client, recorder record.EventRecorder, rl *RateLimiter) SandboxControl {
func NewCommonControl(args SandboxControlArgs) SandboxControl {
control := &commonControl{
Client: c,
recorder: recorder,
inplaceUpdateControl: inplaceupdate.NewInPlaceUpdateControl(c, inplaceupdate.DefaultGeneratePatchBodyFunc),
rateLimiter: rl,
Client: args.Client,
recorder: args.Recorder,
inplaceUpdateControl: inplaceupdate.NewInPlaceUpdateControl(args.Client, inplaceupdate.DefaultGeneratePatchBodyFunc),
rateLimiter: args.RateLimiter,
}
return control
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func handleInPlaceUpdateCommon(
) (bool, error) {
logger := handler.GetLogger(ctx, box)

_, hashImmutablePart := HashSandbox(box)
_, hashImmutablePart := utils.HashSandbox(box)

// old Pod do not include Labels[pod-template-hash] and do not support inplace update.
// Check if inplace update is supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/client-go/tools/record"

agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
"github.com/openkruise/agents/pkg/utils"
"github.com/openkruise/agents/pkg/utils/inplaceupdate"
)

Expand Down Expand Up @@ -313,7 +314,7 @@ func TestHandleInPlaceUpdateCommon_QoSChangeRejected(t *testing.T) {
},
}

_, hashWithoutImageAndResource := HashSandbox(&agentsv1alpha1.Sandbox{
_, hashWithoutImageAndResource := utils.HashSandbox(&agentsv1alpha1.Sandbox{
Spec: agentsv1alpha1.SandboxSpec{
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{
Expand Down Expand Up @@ -438,7 +439,7 @@ func TestHandleInPlaceUpdateCommon_ResizeInfeasibleFailFast(t *testing.T) {
},
}

_, hashWithoutImageAndResource := HashSandbox(&agentsv1alpha1.Sandbox{
_, hashWithoutImageAndResource := utils.HashSandbox(&agentsv1alpha1.Sandbox{
Spec: agentsv1alpha1.SandboxSpec{
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{Spec: pod.Spec},
Expand Down Expand Up @@ -539,7 +540,7 @@ func TestHandleInPlaceUpdateCommon_TerminalFailureNotOverwritten(t *testing.T) {
},
}

_, hashWithoutImageAndResource := HashSandbox(&agentsv1alpha1.Sandbox{
_, hashWithoutImageAndResource := utils.HashSandbox(&agentsv1alpha1.Sandbox{
Spec: agentsv1alpha1.SandboxSpec{
EmbeddedSandboxTemplate: agentsv1alpha1.EmbeddedSandboxTemplate{
Template: &corev1.PodTemplateSpec{Spec: pod.Spec},
Expand Down
14 changes: 12 additions & 2 deletions pkg/controller/sandbox/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
"github.com/openkruise/agents/pkg/sandbox-manager/clients"
"github.com/openkruise/agents/pkg/sandbox-manager/infra/sandboxcr"
"github.com/openkruise/agents/pkg/utils/expectations"
"github.com/openkruise/agents/pkg/utils/inplaceupdate"
)
Expand Down Expand Up @@ -59,9 +61,17 @@ type SandboxControl interface {
EnsureSandboxTerminated(ctx context.Context, args EnsureFuncArgs) error
}

func NewSandboxControl(c client.Client, recorder record.EventRecorder, rl *RateLimiter) map[string]SandboxControl {
type SandboxControlArgs struct {
Client client.Client
Recorder record.EventRecorder
RateLimiter *RateLimiter
SandboxClient *clients.ClientSet
Cache *sandboxcr.Cache
}

func NewSandboxControl(args SandboxControlArgs) map[string]SandboxControl {
controls := map[string]SandboxControl{}
controls[CommonControlName] = NewCommonControl(c, recorder, rl)
controls[CommonControlName] = NewCommonControl(args)
return controls
}

Expand Down
37 changes: 0 additions & 37 deletions pkg/controller/sandbox/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package core

import (
"context"
"encoding/json"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand All @@ -32,42 +31,6 @@ import (
"github.com/openkruise/agents/pkg/utils"
)

// HashSandbox calculates the hash value using sandbox.spec.template
func HashSandbox(box *agentsv1alpha1.Sandbox) (string, string) {
if box.Spec.Template == nil {
if box.Spec.TemplateRef == nil {
return "", ""
}
// templateRef mode does not carry inline PodTemplate in Sandbox spec.
// Use TemplateRef itself as a stable revision key to avoid nil dereference.
by, _ := json.Marshal(box.Spec.TemplateRef)
hash := utils.HashData(by)
return hash, hash
}

// hash using sandbox.spec.template
by, _ := json.Marshal(*box.Spec.Template)
hash := utils.HashData(by)

// hash using sandbox.spec.template without image and resources
tempClone := box.Spec.Template.DeepCopy()
tempClone.Labels = nil
tempClone.Annotations = nil
for i := range tempClone.Spec.Containers {
container := &tempClone.Spec.Containers[i]
container.Image = ""
container.Resources = corev1.ResourceRequirements{}
}
for i := range tempClone.Spec.InitContainers {
container := &tempClone.Spec.InitContainers[i]
container.Image = ""
container.Resources = corev1.ResourceRequirements{}
}
by, _ = json.Marshal(*tempClone)
hashImmutablePart := utils.HashData(by)
return hash, hashImmutablePart
}

// GeneratePVCName generates a persistent volume claim name from template name and sandbox name
func GeneratePVCName(templateName, sandboxName string) (string, error) {
if templateName == "" || sandboxName == "" {
Expand Down
Loading
Loading