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

add taints for node #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions pkg/providers/ack/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
ackclient "github.com/alibabacloud-go/cs-20151215/v5/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/patrickmn/go-cache"
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/log"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"

Expand All @@ -39,7 +41,7 @@ import (
const defaultNodeLabel = "k8s.aliyun.com=true"

type Provider interface {
GetNodeRegisterScript(context.Context, map[string]string, *v1alpha1.KubeletConfiguration) (string, error)
GetNodeRegisterScript(context.Context, map[string]string, *karpv1.NodeClaim, *v1alpha1.KubeletConfiguration) (string, error)
GetClusterCNI(context.Context) (string, error)
LivenessProbe(*http.Request) error
}
Expand Down Expand Up @@ -105,9 +107,10 @@ func (p *DefaultProvider) GetClusterCNI(_ context.Context) (string, error) {

func (p *DefaultProvider) GetNodeRegisterScript(ctx context.Context,
labels map[string]string,
nodeClaim *karpv1.NodeClaim,
kubeletCfg *v1alpha1.KubeletConfiguration) (string, error) {
if cachedScript, ok := p.cache.Get(p.clusterID); ok {
return p.resolveUserData(cachedScript.(string), labels, kubeletCfg), nil
return p.resolveUserData(cachedScript.(string), labels, nodeClaim, kubeletCfg), nil
}

reqPara := &ackclient.DescribeClusterAttachScriptsRequest{
Expand All @@ -126,14 +129,14 @@ func (p *DefaultProvider) GetNodeRegisterScript(ctx context.Context,
}

p.cache.SetDefault(p.clusterID, s)
return p.resolveUserData(s, labels, kubeletCfg), nil
return p.resolveUserData(s, labels, nodeClaim, kubeletCfg), nil
}

func (p *DefaultProvider) resolveUserData(respStr string,
labels map[string]string,
nodeClaim *karpv1.NodeClaim,
kubeletCfg *v1alpha1.KubeletConfiguration) string {
cleanupStr := strings.ReplaceAll(respStr, "\r\n", "")

// TODO: now, the following code is quite ugly, make it clean in the future
// Add labels
labelsFormated := fmt.Sprintf("%s,ack.aliyun.com=%s", defaultNodeLabel, p.clusterID)
Expand All @@ -148,8 +151,19 @@ func (p *DefaultProvider) resolveUserData(respStr string,
updatedCommand = fmt.Sprintf("%s --node-config %s", updatedCommand, cfg)

// Add taints
taint := karpv1.UnregisteredNoExecuteTaint
jxs1211 marked this conversation as resolved.
Show resolved Hide resolved
updatedCommand = fmt.Sprintf("%s --taints %s", updatedCommand, taint.ToString())
taints := lo.Flatten([][]corev1.Taint{
nodeClaim.Spec.Taints,
nodeClaim.Spec.StartupTaints,
})
if !lo.ContainsBy(taints, func(t corev1.Taint) bool {
return t.MatchTaint(&karpv1.UnregisteredNoExecuteTaint)
}) {
taints = append(taints, karpv1.UnregisteredNoExecuteTaint)
}
updatedCommand = fmt.Sprintf("%s --taints %s",
updatedCommand, strings.Join(lo.Map(taints, func(t corev1.Taint, _ int) string {
return t.ToString()
}), ","))

// Add bash script header
finalScript := fmt.Sprintf("#!/bin/bash\n\n%s", updatedCommand)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@

kubeletCfg := resolveKubeletConfiguration(nodeClass)
labels := lo.Assign(nodeClaim.Labels, map[string]string{karpv1.CapacityTypeLabelKey: capacityType})
userData, err := p.ackProvider.GetNodeRegisterScript(ctx, labels, kubeletCfg)
userData, err := p.ackProvider.GetNodeRegisterScript(ctx, labels, nodeClaim.Spec.Taints, kubeletCfg)

Check failure on line 506 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / presubmit

cannot use nodeClaim.Spec.Taints (variable of type []"k8s.io/api/core/v1".Taint) as *"sigs.k8s.io/karpenter/pkg/apis/v1".NodeClaim value in argument to p.ackProvider.GetNodeRegisterScript (typecheck)

Check failure on line 506 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / presubmit

cannot use nodeClaim.Spec.Taints (variable of type []"k8s.io/api/core/v1".Taint) as *"sigs.k8s.io/karpenter/pkg/apis/v1".NodeClaim value in argument to p.ackProvider.GetNodeRegisterScript) (typecheck)

Check failure on line 506 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / presubmit

cannot use nodeClaim.Spec.Taints (variable of type []"k8s.io/api/core/v1".Taint) as *"sigs.k8s.io/karpenter/pkg/apis/v1".NodeClaim value in argument to p.ackProvider.GetNodeRegisterScript) (typecheck)

Check failure on line 506 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / presubmit

cannot use nodeClaim.Spec.Taints (variable of type []"k8s.io/api/core/v1".Taint) as *"sigs.k8s.io/karpenter/pkg/apis/v1".NodeClaim value in argument to p.ackProvider.GetNodeRegisterScript) (typecheck)
if err != nil {
log.FromContext(ctx).Error(err, "Failed to resolve user data for node")
return nil, err
Expand Down
Loading