diff --git a/actions/actions.go b/actions/actions.go index 901b21e5..ea374309 100644 --- a/actions/actions.go +++ b/actions/actions.go @@ -36,6 +36,7 @@ type ActionHandler interface { func NewService( log logrus.FieldLogger, cfg Config, + k8sVersion string, clientset *kubernetes.Clientset, castaiClient castai.Client, helmClient helm.Client, @@ -43,6 +44,7 @@ func NewService( return &service{ log: log, cfg: cfg, + k8sVersion: k8sVersion, castaiClient: castaiClient, startedActions: map[string]struct{}{}, actionHandlers: map[reflect.Type]ActionHandler{ @@ -64,6 +66,8 @@ type service struct { cfg Config castaiClient castai.Client + k8sVersion string + actionHandlers map[reflect.Type]ActionHandler startedActionsWg sync.WaitGroup @@ -114,7 +118,7 @@ func (s *service) doWork(ctx context.Context) error { func (s *service) pollActions(ctx context.Context) ([]*castai.ClusterAction, error) { ctx, cancel := context.WithTimeout(ctx, s.cfg.PollTimeout) defer cancel() - actions, err := s.castaiClient.GetActions(ctx) + actions, err := s.castaiClient.GetActions(ctx, s.k8sVersion) if err != nil { return nil, err } diff --git a/actions/actions_test.go b/actions/actions_test.go index d462a452..71bdd515 100644 --- a/actions/actions_test.go +++ b/actions/actions_test.go @@ -33,7 +33,14 @@ func TestActions(t *testing.T) { } newTestService := func(handler ActionHandler, client castai.Client) *service { - svc := NewService(log, cfg, nil, client, nil).(*service) + svc := NewService( + log, + cfg, + "1.20.1", + nil, + client, + nil, + ).(*service) handlers := svc.actionHandlers // Patch handlers with a mock one. for k := range handlers { diff --git a/castai/client.go b/castai/client.go index 5e442f42..f07b0939 100644 --- a/castai/client.go +++ b/castai/client.go @@ -13,12 +13,13 @@ import ( ) const ( - headerAPIKey = "X-API-Key" - headerUserAgent = "User-Agent" + headerAPIKey = "X-API-Key" + headerUserAgent = "User-Agent" + headerKubernetesVersion = "X-K8s-Version" ) type Client interface { - GetActions(ctx context.Context) ([]*ClusterAction, error) + GetActions(ctx context.Context, k8sVersion string) ([]*ClusterAction, error) AckAction(ctx context.Context, actionID string, req *AckClusterActionRequest) error SendLogs(ctx context.Context, req *LogEvent) error SendAKSInitData(ctx context.Context, req *AKSInitDataRequest) error @@ -84,11 +85,12 @@ func (c *client) SendLogs(ctx context.Context, req *LogEvent) error { return nil } -func (c *client) GetActions(ctx context.Context) ([]*ClusterAction, error) { +func (c *client) GetActions(ctx context.Context, k8sVersion string) ([]*ClusterAction, error) { res := &GetClusterActionsResponse{} resp, err := c.rest.R(). SetContext(ctx). SetResult(res). + SetHeader(headerKubernetesVersion, k8sVersion). Get(fmt.Sprintf("/v1/kubernetes/clusters/%s/actions", c.clusterID)) if err != nil { return nil, fmt.Errorf("failed to request cluster-actions: %w", err) diff --git a/castai/mock/client.go b/castai/mock/client.go index 9a925ab2..49a5060f 100644 --- a/castai/mock/client.go +++ b/castai/mock/client.go @@ -35,7 +35,7 @@ func (m *mockClient) SendAKSInitData(ctx context.Context, req *castai.AKSInitDat return nil } -func (m *mockClient) GetActions(_ context.Context) ([]*castai.ClusterAction, error) { +func (m *mockClient) GetActions(_ context.Context, _ string) ([]*castai.ClusterAction, error) { m.mu.Lock() actions := m.Actions m.mu.Unlock() diff --git a/main.go b/main.go index b855d241..12060311 100644 --- a/main.go +++ b/main.go @@ -130,7 +130,14 @@ func run( AckRetryWait: 1 * time.Second, ClusterID: cfg.ClusterID, } - svc := actions.NewService(log, actionsConfig, clientset, client, helmClient) + svc := actions.NewService( + log, + actionsConfig, + k8sVersion.Full(), + clientset, + client, + helmClient, + ) if cfg.LeaderElection.Enabled { lock, err := newLeaseLock(clientset, cfg.LeaderElection.LockName, cfg.LeaderElection.Namespace)