@@ -30,6 +30,8 @@ import (
30
30
ackclient "github.com/alibabacloud-go/cs-20151215/v5/client"
31
31
"github.com/alibabacloud-go/tea/tea"
32
32
"github.com/patrickmn/go-cache"
33
+ "github.com/samber/lo"
34
+ corev1 "k8s.io/api/core/v1"
33
35
"sigs.k8s.io/controller-runtime/pkg/log"
34
36
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
35
37
@@ -39,7 +41,7 @@ import (
39
41
const defaultNodeLabel = "k8s.aliyun.com=true"
40
42
41
43
type Provider interface {
42
- GetNodeRegisterScript (context.Context , map [ string ] string , * v1alpha1.KubeletConfiguration ) (string , error )
44
+ GetNodeRegisterScript (context.Context , string , * karpv1. NodeClaim , * v1alpha1.KubeletConfiguration ) (string , error )
43
45
GetClusterCNI (context.Context ) (string , error )
44
46
LivenessProbe (* http.Request ) error
45
47
}
@@ -104,10 +106,12 @@ func (p *DefaultProvider) GetClusterCNI(_ context.Context) (string, error) {
104
106
}
105
107
106
108
func (p * DefaultProvider ) GetNodeRegisterScript (ctx context.Context ,
107
- labels map [string ]string ,
109
+ capacityType string ,
110
+ nodeClaim * karpv1.NodeClaim ,
108
111
kubeletCfg * v1alpha1.KubeletConfiguration ) (string , error ) {
112
+ labels := lo .Assign (nodeClaim .Labels , map [string ]string {karpv1 .CapacityTypeLabelKey : capacityType })
109
113
if cachedScript , ok := p .cache .Get (p .clusterID ); ok {
110
- return p .resolveUserData (cachedScript .(string ), labels , kubeletCfg ), nil
114
+ return p .resolveUserData (cachedScript .(string ), labels , nodeClaim , kubeletCfg ), nil
111
115
}
112
116
113
117
reqPara := & ackclient.DescribeClusterAttachScriptsRequest {
@@ -126,14 +130,14 @@ func (p *DefaultProvider) GetNodeRegisterScript(ctx context.Context,
126
130
}
127
131
128
132
p .cache .SetDefault (p .clusterID , s )
129
- return p .resolveUserData (s , labels , kubeletCfg ), nil
133
+ return p .resolveUserData (s , labels , nodeClaim , kubeletCfg ), nil
130
134
}
131
135
132
136
func (p * DefaultProvider ) resolveUserData (respStr string ,
133
137
labels map [string ]string ,
138
+ nodeClaim * karpv1.NodeClaim ,
134
139
kubeletCfg * v1alpha1.KubeletConfiguration ) string {
135
140
cleanupStr := strings .ReplaceAll (respStr , "\r \n " , "" )
136
-
137
141
// TODO: now, the following code is quite ugly, make it clean in the future
138
142
// Add labels
139
143
labelsFormated := fmt .Sprintf ("%s,ack.aliyun.com=%s" , defaultNodeLabel , p .clusterID )
@@ -148,8 +152,19 @@ func (p *DefaultProvider) resolveUserData(respStr string,
148
152
updatedCommand = fmt .Sprintf ("%s --node-config %s" , updatedCommand , cfg )
149
153
150
154
// Add taints
151
- taint := karpv1 .UnregisteredNoExecuteTaint
152
- updatedCommand = fmt .Sprintf ("%s --taints %s" , updatedCommand , taint .ToString ())
155
+ taints := lo .Flatten ([][]corev1.Taint {
156
+ nodeClaim .Spec .Taints ,
157
+ nodeClaim .Spec .StartupTaints ,
158
+ })
159
+ if ! lo .ContainsBy (taints , func (t corev1.Taint ) bool {
160
+ return t .MatchTaint (& karpv1 .UnregisteredNoExecuteTaint )
161
+ }) {
162
+ taints = append (taints , karpv1 .UnregisteredNoExecuteTaint )
163
+ }
164
+ updatedCommand = fmt .Sprintf ("%s --taints %s" ,
165
+ updatedCommand , strings .Join (lo .Map (taints , func (t corev1.Taint , _ int ) string {
166
+ return t .ToString ()
167
+ }), "," ))
153
168
154
169
// Add bash script header
155
170
finalScript := fmt .Sprintf ("#!/bin/bash\n \n %s" , updatedCommand )
0 commit comments