From 4650ad75a25c41c0ebe4b3044e0a3a38ac56d185 Mon Sep 17 00:00:00 2001 From: Shane Jarych Date: Thu, 28 Apr 2022 16:56:42 +0000 Subject: [PATCH] Add an 'id' to plan command status Adding an identifier to plan command status fixes a problem in signal node reconciliation where multiple commands of the same name (ie. k0supdate + k0supdate) wouldn't be possible. This also removes the redundant 'CommandUpdateItem' struct in favor for embedding the 'k0s' and 'airgap' update structs into the 'Command' struct. This aligns better with the CRD structures. This is a breaking change. Fixes #227 Signed-off-by: Shane Jarych --- .../autopilot.k0sproject.io_plans.yaml | 13 +- ...autopilot.k0sproject.io_updateconfigs.yaml | 8 +- .../autopilot.k0sproject.io/v1beta2/types.go | 3 + .../cmdprovider/k0supdate/schedulable.go | 25 ++-- .../cmdprovider/k0supdate/schedulable_test.go | 1 + .../cmdprovider/k0supdate/schedulablewait.go | 8 +- .../k0supdate/schedulablewait_test.go | 24 ++-- .../controller/plans/core/planstatehandler.go | 6 +- .../pkg/controller/signal/airgap/download.go | 4 +- .../pkg/controller/signal/airgap/init.go | 2 +- .../pkg/controller/signal/airgap/init_test.go | 10 +- .../controller/signal/airgap/signal_test.go | 76 +++++------ .../pkg/controller/signal/common/download.go | 4 +- .../controller/signal/common/signal_test.go | 22 ++- autopilot/pkg/controller/signal/k0s/apply.go | 2 +- .../pkg/controller/signal/k0s/apply_test.go | 118 +++++++++------- .../pkg/controller/signal/k0s/download.go | 4 +- .../controller/signal/k0s/download_test.go | 39 +++--- autopilot/pkg/controller/signal/k0s/init.go | 2 +- .../pkg/controller/signal/k0s/init_test.go | 10 +- .../pkg/controller/signal/k0s/restart.go | 2 +- autopilot/pkg/controller/signal/k0s/signal.go | 4 +- .../pkg/controller/signal/k0s/signal_test.go | 127 +++++++++--------- autopilot/pkg/signaling/v2/signaling_v2.go | 42 ++---- .../pkg/signaling/v2/signaling_v2_test.go | 34 +++-- 25 files changed, 288 insertions(+), 302 deletions(-) diff --git a/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_plans.yaml b/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_plans.yaml index 73a9f3e3b218..38af192f863a 100644 --- a/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_plans.yaml +++ b/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_plans.yaml @@ -55,21 +55,21 @@ spec: properties: platforms: additionalProperties: - description: PlanResourceUrl is a remote Url resource. + description: PlanResourceURL is a remote URL resource. properties: sha256: description: Sha256 provides an optional SHA256 hash - of the Url's content for verification. + of the URL's content for verification. type: string url: - description: Url is the Url of a downloadable resource. + description: URL is the URL of a downloadable resource. type: string required: - url type: object description: Platforms is a map of PlanResourceUrls to platform identifiers, allowing a single k0s version to have multiple - Url resources based on platform. + URL resources based on platform. type: object targets: description: Targets defines how the controllers/workers @@ -209,6 +209,10 @@ spec: items: description: PlanCommandStatus is the status of a known command. properties: + id: + description: Id is a unique identifier for this command in a + Plan + type: integer k0supdate: description: K0sUpdate is the status of the `K0sUpdate` command. properties: @@ -267,6 +271,7 @@ spec: description: State is the current state of the plan command. type: string required: + - id - state type: object type: array diff --git a/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_updateconfigs.yaml b/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_updateconfigs.yaml index 5364380eee46..26ca212b4cde 100644 --- a/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_updateconfigs.yaml +++ b/autopilot/embedded/manifests/autopilot.k0sproject.io/v1beta2/autopilot.k0sproject.io_updateconfigs.yaml @@ -52,14 +52,14 @@ spec: properties: platforms: additionalProperties: - description: PlanResourceUrl is a remote Url resource. + description: PlanResourceURL is a remote URL resource. properties: sha256: description: Sha256 provides an optional SHA256 - hash of the Url's content for verification. + hash of the URL's content for verification. type: string url: - description: Url is the Url of a downloadable + description: URL is the URL of a downloadable resource. type: string required: @@ -67,7 +67,7 @@ spec: type: object description: Platforms is a map of PlanResourceUrls to platform identifiers, allowing a single k0s version - to have multiple Url resources based on platform. + to have multiple URL resources based on platform. type: object targets: description: Targets defines how the controllers/workers diff --git a/autopilot/pkg/apis/autopilot.k0sproject.io/v1beta2/types.go b/autopilot/pkg/apis/autopilot.k0sproject.io/v1beta2/types.go index 42279f2c0c58..18dab1b41454 100644 --- a/autopilot/pkg/apis/autopilot.k0sproject.io/v1beta2/types.go +++ b/autopilot/pkg/apis/autopilot.k0sproject.io/v1beta2/types.go @@ -212,6 +212,9 @@ type PlanStatus struct { // PlanCommandStatus is the status of a known command. type PlanCommandStatus struct { + // Id is a unique identifier for this command in a Plan + Id int `json:"id"` + // State is the current state of the plan command. State PlanStateType `json:"state"` diff --git a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable.go b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable.go index 24073cc15a9b..1aa4ef1fd5f3 100644 --- a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable.go +++ b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable.go @@ -89,7 +89,7 @@ func (kp *k0supdate) Schedulable(ctx context.Context, cmd apv1beta2.PlanCommand, // This has the possibility of ending reconciliation early if the node and plan platforms // disagree. This target state will move to `IncompleteTargets` in this case. - nodeCopy, err := signalNodeUpdate(signalNodeDelegate.DeepCopy(signalNode), cmd.K0sUpdate, status.K0sUpdate) + nodeCopy, err := signalNodeUpdate(signalNodeDelegate.DeepCopy(signalNode), cmd, status) if err != nil { logger.Warnf("Unable to update signal node: %v", err) return appc.PlanIncompleteTargets, false, nil @@ -170,30 +170,33 @@ func findNextPendingRandom(nodes []apv1beta2.PlanCommandTargetStatus) (*apv1beta } // signalNodeUpdate builds a signalling update request, and adds it to the provided node -func signalNodeUpdate(node crcli.Object, cmd *apv1beta2.PlanCommandK0sUpdate, cmdStatus *apv1beta2.PlanCommandK0sUpdateStatus) (crcli.Object, error) { +func signalNodeUpdate(node crcli.Object, cmd apv1beta2.PlanCommand, cmdStatus *apv1beta2.PlanCommandStatus) (crcli.Object, error) { + if cmdStatus == nil || cmd.K0sUpdate == nil || cmdStatus.K0sUpdate == nil { + return nil, fmt.Errorf("invalid plan command arguments for k0supdate") + } + // Determine the platform identifier of the target signal node nodePlatformID, err := signalNodePlatformIdentifier(node) if err != nil { - updatePlanCommandTargetStatusByName(node.GetName(), appc.SignalMissingPlatform, cmdStatus) + updatePlanCommandTargetStatusByName(node.GetName(), appc.SignalMissingPlatform, cmdStatus.K0sUpdate) return nil, err } // Find the appropriate update content for this signal node - updateContent, updateContentOk := cmd.Platforms[nodePlatformID] + updateContent, updateContentOk := cmd.K0sUpdate.Platforms[nodePlatformID] if !updateContentOk { - updatePlanCommandTargetStatusByName(node.GetName(), appc.SignalMissingPlatform, cmdStatus) + updatePlanCommandTargetStatusByName(node.GetName(), appc.SignalMissingPlatform, cmdStatus.K0sUpdate) return nil, err } signalData := apsigv2.SignalData{ Created: time.Now().Format(time.RFC3339), Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{ - URL: updateContent.URL, - Version: cmd.Version, - Sha256: updateContent.Sha256, - }, + ID: &cmdStatus.Id, + K0sUpdate: &apsigv2.CommandK0sUpdate{ + URL: updateContent.URL, + Version: cmd.K0sUpdate.Version, + Sha256: updateContent.Sha256, }, }, } diff --git a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable_test.go b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable_test.go index df5366c9afa6..70a00ce744e8 100644 --- a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable_test.go +++ b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulable_test.go @@ -138,6 +138,7 @@ func TestSchedulable(t *testing.T) { }, }, apv1beta2.PlanCommandStatus{ + Id: 123, State: appc.PlanSchedulable, K0sUpdate: &apv1beta2.PlanCommandK0sUpdateStatus{ Controllers: []apv1beta2.PlanCommandTargetStatus{ diff --git a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait.go b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait.go index 48cf239f5fc9..d6d011b050d3 100644 --- a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait.go +++ b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait.go @@ -130,16 +130,10 @@ func (kp *k0supdate) reconcileSignalNodeStatusTarget(ctx context.Context, cmd ap // isSignalDataSameCommand determines if the `PlanCommand` and the command specified in the signal data represent // the same command. func isSignalDataSameCommand(cmd apv1beta2.PlanCommand, signalData apsigv2.SignalData) bool { - update := signalData.Command.Update - if update == nil { - return false - } - // As additional commands are implemented, they will need to be reflected here. - switch { case cmd.K0sUpdate != nil: - return update.K0s != nil + return signalData.Command.K0sUpdate != nil } return false diff --git a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait_test.go b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait_test.go index df588a7c3184..0731e9511244 100644 --- a/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait_test.go +++ b/autopilot/pkg/controller/plans/cmdprovider/k0supdate/schedulablewait_test.go @@ -279,11 +279,10 @@ func TestSchedulableWait(t *testing.T) { apsigv2.SignalData{ Created: "now", Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{ - URL: "https://foo.bar.baz/download.tar.gz", - Version: "v1.2.3", - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{ + URL: "https://foo.bar.baz/download.tar.gz", + Version: "v1.2.3", }, }, Status: &apsigv2.Status{ @@ -460,9 +459,8 @@ func TestIsSignalDataSameCommand(t *testing.T) { }, apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{}, - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{}, }, }, true, @@ -482,9 +480,8 @@ func TestIsSignalDataSameCommand(t *testing.T) { apv1beta2.PlanCommand{}, apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{}, - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{}, }, }, false, @@ -496,9 +493,8 @@ func TestIsSignalDataSameCommand(t *testing.T) { }, apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - Airgap: &apsigv2.CommandUpdateItemAirgap{}, - }, + ID: new(int), + AirgapUpdate: &apsigv2.CommandAirgapUpdate{}, }, }, false, diff --git a/autopilot/pkg/controller/plans/core/planstatehandler.go b/autopilot/pkg/controller/plans/core/planstatehandler.go index 5711ad05f0db..a6ebcaa79c7a 100644 --- a/autopilot/pkg/controller/plans/core/planstatehandler.go +++ b/autopilot/pkg/controller/plans/core/planstatehandler.go @@ -127,7 +127,7 @@ func findPlanCommandStatus(status *apv1beta2.PlanStatus, idx int) *apv1beta2.Pla } // .. otherwise, add a new one and return it - status.Commands = append(status.Commands, apv1beta2.PlanCommandStatus{}) + status.Commands = append(status.Commands, apv1beta2.PlanCommandStatus{Id: idx}) return &status.Commands[len(status.Commands)-1] } @@ -142,7 +142,9 @@ func (h *planStateHandler) planCommandProviderLookup(cmd apv1beta2.PlanCommand) rpcmd := reflect.Indirect(reflect.ValueOf(cmd)) for i := 0; i < rpcmd.NumField(); i++ { - if v := rpcmd.Field(i); !v.IsNil() { + v := rpcmd.Field(i) + + if v.Kind() == reflect.Pointer && !v.IsNil() { fieldName := rpcmd.Type().Field(i).Name if handler, found := h.commandProviderMap[fieldName]; found { return fieldName, handler, true diff --git a/autopilot/pkg/controller/signal/airgap/download.go b/autopilot/pkg/controller/signal/airgap/download.go index 843a5d503969..07a338f9242b 100644 --- a/autopilot/pkg/controller/signal/airgap/download.go +++ b/autopilot/pkg/controller/signal/airgap/download.go @@ -59,8 +59,8 @@ func registerDownloadController(logger *logrus.Entry, mgr crman.Manager, eventFi func (b downloadManfiestBuilderAirgap) Build(signalNode crcli.Object, signalData apsigv2.SignalData) (apsigcomm.DownloadManifest, error) { m := apsigcomm.DownloadManifest{ Config: apdl.Config{ - URL: signalData.Command.Update.Airgap.URL, - ExpectedHash: signalData.Command.Update.Airgap.Sha256, + URL: signalData.Command.AirgapUpdate.URL, + ExpectedHash: signalData.Command.AirgapUpdate.Sha256, Hasher: sha256.New(), DownloadDir: path.Join(b.k0sDataDir, apconst.K0sManifestSubDir), }, diff --git a/autopilot/pkg/controller/signal/airgap/init.go b/autopilot/pkg/controller/signal/airgap/init.go index cfdb839748c8..fc281f2e4b29 100644 --- a/autopilot/pkg/controller/signal/airgap/init.go +++ b/autopilot/pkg/controller/signal/airgap/init.go @@ -56,6 +56,6 @@ func RegisterControllers(ctx context.Context, logger *logrus.Entry, mgr crman.Ma // provided SignalData is an 'airgap' update. func signalDataUpdateCommandAirgapPredicate() apsigpred.SignalDataPredicate { return func(signalData apsigv2.SignalData) bool { - return signalData.Command.Update != nil && signalData.Command.Update.Airgap != nil + return signalData.Command.AirgapUpdate != nil } } diff --git a/autopilot/pkg/controller/signal/airgap/init_test.go b/autopilot/pkg/controller/signal/airgap/init_test.go index 2f4bd83c8c94..f1ee78370494 100644 --- a/autopilot/pkg/controller/signal/airgap/init_test.go +++ b/autopilot/pkg/controller/signal/airgap/init_test.go @@ -34,9 +34,8 @@ func TestSignalDataUpdateCommandAirgapPredicate(t *testing.T) { "Found", apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - Airgap: &apsigv2.CommandUpdateItemAirgap{}, - }, + ID: new(int), + AirgapUpdate: &apsigv2.CommandAirgapUpdate{}, }, }, true, @@ -45,9 +44,8 @@ func TestSignalDataUpdateCommandAirgapPredicate(t *testing.T) { "NotFoundK0s", apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{}, - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{}, }, }, false, diff --git a/autopilot/pkg/controller/signal/airgap/signal_test.go b/autopilot/pkg/controller/signal/airgap/signal_test.go index 7db9d1807a7f..cf646cfe19fd 100644 --- a/autopilot/pkg/controller/signal/airgap/signal_test.go +++ b/autopilot/pkg/controller/signal/airgap/signal_test.go @@ -67,13 +67,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "airgap": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "airgapupdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -106,13 +105,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } }, "status": { @@ -139,13 +137,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -167,13 +164,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -206,13 +202,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -249,12 +244,11 @@ func TestHandle(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "airgap": { - "version": "v1.23.3+k0s.1", - "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.1/k0s-airgap-bundle-v1.23.3+k0s.1-amd64", - "sha256": "258f3edd0c260a23c579406f5cc04a599a6f59cc1707f9bd523d7a9abc07f0e2" - } + "id": 123, + "airgapupdate": { + "version": "v1.23.3+k0s.1", + "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.1/k0s-airgap-bundle-v1.23.3+k0s.1-amd64", + "sha256": "258f3edd0c260a23c579406f5cc04a599a6f59cc1707f9bd523d7a9abc07f0e2" } } } diff --git a/autopilot/pkg/controller/signal/common/download.go b/autopilot/pkg/controller/signal/common/download.go index 7c91c4a62a17..a26010452c09 100644 --- a/autopilot/pkg/controller/signal/common/download.go +++ b/autopilot/pkg/controller/signal/common/download.go @@ -83,13 +83,13 @@ func (r *downloadController) Reconcile(ctx context.Context, req cr.Request) (cr. httpdl := apdl.NewDownloader(manifest.Config, logger) if err := httpdl.Download(ctx); err != nil { - logger.Errorf("Unable to download '%s': %v", signalData.Command.Update.K0s.URL, err) + logger.Errorf("Unable to download '%s': %v", manifest.URL, err) // When the download is complete move the status to `FailedDownload` signalData.Status = apsigv2.NewStatus(FailedDownload) } else { - logger.Infof("Download of '%s' successful", signalData.Command.Update.K0s.URL) + logger.Infof("Download of '%s' successful", manifest.URL) // When the download is complete move the status to the success state signalData.Status = apsigv2.NewStatus(manifest.SuccessState) diff --git a/autopilot/pkg/controller/signal/common/signal_test.go b/autopilot/pkg/controller/signal/common/signal_test.go index 1d9953cdd498..fe08bc0dffc5 100644 --- a/autopilot/pkg/controller/signal/common/signal_test.go +++ b/autopilot/pkg/controller/signal/common/signal_test.go @@ -47,12 +47,11 @@ func TestExtractSignalData(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "sha256": "thisisthesha" } } } @@ -72,12 +71,11 @@ func TestExtractSignalData(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "sha256": "thisisthesha" } }, "status": { diff --git a/autopilot/pkg/controller/signal/k0s/apply.go b/autopilot/pkg/controller/signal/k0s/apply.go index 12d0f38294f8..bbefd7d3ec1f 100644 --- a/autopilot/pkg/controller/signal/k0s/apply.go +++ b/autopilot/pkg/controller/signal/k0s/apply.go @@ -100,7 +100,7 @@ func (r *applyingUpdate) Reconcile(ctx context.Context, req cr.Request) (cr.Resu } // Get the filename fragment from the URL - updateURL, err := url.Parse(signalData.Command.Update.K0s.URL) + updateURL, err := url.Parse(signalData.Command.K0sUpdate.URL) if err != nil { return cr.Result{}, fmt.Errorf("unable to get update request URL: %w", err) } diff --git a/autopilot/pkg/controller/signal/k0s/apply_test.go b/autopilot/pkg/controller/signal/k0s/apply_test.go index 997b0fbf06de..8f3ccdff2282 100644 --- a/autopilot/pkg/controller/signal/k0s/apply_test.go +++ b/autopilot/pkg/controller/signal/k0s/apply_test.go @@ -55,13 +55,12 @@ func TestApplyingUpdateEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.23.3+k0s.0", - "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" - } + "id": 123, + "k0supdate": { + "version": "v1.23.3+k0s.0", + "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" } }, "status": { @@ -98,13 +97,12 @@ func TestApplyingUpdateEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.23.3+k0s.0", - "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" - } + "id": 123, + "k0supdate": { + "version": "v1.23.3+k0s.0", + "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" } }, "status": { @@ -125,18 +123,24 @@ func TestApplyingUpdateEventFilter(t *testing.T) { ObjectOld: &apv1beta2.ControlNode{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "k0sproject.io/autopilot-version": "v1beta2", - "k0sproject.io/autopilot-command": "update", - "k0sproject.io/autopilot-command-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-command-timestamp": "2021-10-20T19:06:56Z", - "k0sproject.io/autopilot-command-update-sha256": "thisisthesha", - "k0sproject.io/autopilot-command-update-url": "https://www.google.com/download.tar.gz", - "k0sproject.io/autopilot-command-update-version": "v1.2.3", - "k0sproject.io/autopilot-plan-id": "id123", - "k0sproject.io/autopilot-response": "Completed", - "k0sproject.io/autopilot-response-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-response-timestamp": "2021-10-20T19:09:11Z", - }}, + "k0sproject.io/autopilot-signal-version": "v2", + "k0sproject.io/autopilot-signal-data": ` + { + "planId":"abc123", + "created":"now", + "command": { + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" + } + } + } + `, + }, + }, }, ObjectNew: &apv1beta2.ControlNode{ TypeMeta: metav1.TypeMeta{ @@ -146,17 +150,26 @@ func TestApplyingUpdateEventFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node0", Annotations: map[string]string{ - "k0sproject.io/autopilot-version": "v1beta2", - "k0sproject.io/autopilot-command": "update", - "k0sproject.io/autopilot-command-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-command-timestamp": "2021-10-20T19:06:56Z", - "k0sproject.io/autopilot-command-update-sha256": "thisisthesha", - "k0sproject.io/autopilot-command-update-url": "https://www.google.com/download.tar.gz", - "k0sproject.io/autopilot-command-update-version": "v1.2.3", - "k0sproject.io/autopilot-plan-id": "id123", - "k0sproject.io/autopilot-response": "Completed", - "k0sproject.io/autopilot-response-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-response-timestamp": "2021-10-20T19:09:11Z", + "k0sproject.io/autopilot-signal-version": "v2", + "k0sproject.io/autopilot-signal-data": ` + { + "planId":"abc123", + "created":"now", + "command": { + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" + } + } + "status": { + "status": "Completed", + "timestamp": "2021-10-20T19:09:11Z" + } + } + `, }, }, }, @@ -179,17 +192,26 @@ func TestApplyingUpdateEventFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "nodeDIFFERENT", Annotations: map[string]string{ - "k0sproject.io/autopilot-version": "v1beta2", - "k0sproject.io/autopilot-command": "update", - "k0sproject.io/autopilot-command-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-command-timestamp": "2021-10-20T19:06:56Z", - "k0sproject.io/autopilot-command-update-sha256": "thisisthesha", - "k0sproject.io/autopilot-command-update-url": "https://www.google.com/download.tar.gz", - "k0sproject.io/autopilot-command-update-version": "v1.2.3", - "k0sproject.io/autopilot-plan-id": "id123", - "k0sproject.io/autopilot-response": "Completed", - "k0sproject.io/autopilot-response-id": "0396fbc9fe1b", - "k0sproject.io/autopilot-response-timestamp": "2021-10-20T19:09:11Z", + "k0sproject.io/autopilot-signal-version": "v2", + "k0sproject.io/autopilot-signal-data": ` + { + "planId":"abc123", + "created":"now", + "command": { + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" + } + } + "status": { + "status": "Completed", + "timestamp": "2021-10-20T19:09:11Z" + } + } + `, }, }, }, diff --git a/autopilot/pkg/controller/signal/k0s/download.go b/autopilot/pkg/controller/signal/k0s/download.go index 1a8705dc95d2..aab9c0cd6f72 100644 --- a/autopilot/pkg/controller/signal/k0s/download.go +++ b/autopilot/pkg/controller/signal/k0s/download.go @@ -81,8 +81,8 @@ func registerDownloading(logger *logrus.Entry, mgr crman.Manager, eventFilter cr func (b downloadManifestBuilderK0s) Build(signalNode crcli.Object, signalData apsigv2.SignalData) (apsigcomm.DownloadManifest, error) { m := apsigcomm.DownloadManifest{ Config: apdl.Config{ - URL: signalData.Command.Update.K0s.URL, - ExpectedHash: signalData.Command.Update.K0s.Sha256, + URL: signalData.Command.K0sUpdate.URL, + ExpectedHash: signalData.Command.K0sUpdate.Sha256, Hasher: sha256.New(), DownloadDir: apconst.K0sBinaryDir, }, diff --git a/autopilot/pkg/controller/signal/k0s/download_test.go b/autopilot/pkg/controller/signal/k0s/download_test.go index 37f6a016d359..31dff85e1758 100644 --- a/autopilot/pkg/controller/signal/k0s/download_test.go +++ b/autopilot/pkg/controller/signal/k0s/download_test.go @@ -55,13 +55,12 @@ func TestDownloadingEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } }, "status": { @@ -88,13 +87,12 @@ func TestDownloadingEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } }, "status": { @@ -120,13 +118,12 @@ func TestDownloadingEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } }, "status": { diff --git a/autopilot/pkg/controller/signal/k0s/init.go b/autopilot/pkg/controller/signal/k0s/init.go index 905af289ee54..b2195f8350cc 100644 --- a/autopilot/pkg/controller/signal/k0s/init.go +++ b/autopilot/pkg/controller/signal/k0s/init.go @@ -102,6 +102,6 @@ func getK0sPid(statusSocketPath string) (int, error) { // provided SignalData is an 'k0s' update. func signalDataUpdateCommandK0sPredicate() apsigpred.SignalDataPredicate { return func(signalData apsigv2.SignalData) bool { - return signalData.Command.Update != nil && signalData.Command.Update.K0s != nil + return signalData.Command.K0sUpdate != nil } } diff --git a/autopilot/pkg/controller/signal/k0s/init_test.go b/autopilot/pkg/controller/signal/k0s/init_test.go index b65f1b6b0ad4..0c4a1c857635 100644 --- a/autopilot/pkg/controller/signal/k0s/init_test.go +++ b/autopilot/pkg/controller/signal/k0s/init_test.go @@ -34,9 +34,8 @@ func TestSignalDataUpdateCommandK0sPredicate(t *testing.T) { "Found", apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{}, - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{}, }, }, true, @@ -45,9 +44,8 @@ func TestSignalDataUpdateCommandK0sPredicate(t *testing.T) { "NotFoundAirgap", apsigv2.SignalData{ Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - Airgap: &apsigv2.CommandUpdateItemAirgap{}, - }, + ID: new(int), + AirgapUpdate: &apsigv2.CommandAirgapUpdate{}, }, }, false, diff --git a/autopilot/pkg/controller/signal/k0s/restart.go b/autopilot/pkg/controller/signal/k0s/restart.go index 426cb95cd3e8..e6ae03b966db 100644 --- a/autopilot/pkg/controller/signal/k0s/restart.go +++ b/autopilot/pkg/controller/signal/k0s/restart.go @@ -115,7 +115,7 @@ func (r *restart) Reconcile(ctx context.Context, req cr.Request) (cr.Result, err return cr.Result{}, fmt.Errorf("unable to unmarshal signal data for node='%s': %w", req.NamespacedName.Name, err) } - if k0sVersion == signalData.Command.Update.K0s.Version { + if k0sVersion == signalData.Command.K0sUpdate.Version { signalNodeCopy := r.delegate.DeepCopy(signalNode) signalData.Status = apsigv2.NewStatus(UnCordoning) diff --git a/autopilot/pkg/controller/signal/k0s/signal.go b/autopilot/pkg/controller/signal/k0s/signal.go index 786980b261de..ea8aa7637d62 100644 --- a/autopilot/pkg/controller/signal/k0s/signal.go +++ b/autopilot/pkg/controller/signal/k0s/signal.go @@ -110,13 +110,13 @@ func (h *signalControllerHandler) Handle(ctx context.Context, sctx apsigcomm.Sig return cr.Result{}, fmt.Errorf("unable to determine k0s version: %w", err) } - sctx.Log.Infof("Current version of k0s = '%s', requested version = '%s'", k0sVersion, sctx.SignalData.Command.Update.K0s.Version) + sctx.Log.Infof("Current version of k0s = '%s', requested version = '%s'", k0sVersion, sctx.SignalData.Command.K0sUpdate.Version) // Only move to 'Downloading' if the requested version doesn't match the current // installed version. Move to 'Completed' otherwise as there is nothing to do. var status string switch k0sVersion { - case sctx.SignalData.Command.Update.K0s.Version: + case sctx.SignalData.Command.K0sUpdate.Version: status = apsigcomm.Completed default: status = Downloading diff --git a/autopilot/pkg/controller/signal/k0s/signal_test.go b/autopilot/pkg/controller/signal/k0s/signal_test.go index 3ceaca753e3c..33f1b423b218 100644 --- a/autopilot/pkg/controller/signal/k0s/signal_test.go +++ b/autopilot/pkg/controller/signal/k0s/signal_test.go @@ -68,13 +68,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -85,6 +84,7 @@ func TestSignalControllerEventFilter(t *testing.T) { }, true, }, + { "Unexpected response", crev.UpdateEvent{ @@ -107,13 +107,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } }, "status": { @@ -128,6 +127,7 @@ func TestSignalControllerEventFilter(t *testing.T) { }, false, }, + { "No change in annotations", crev.UpdateEvent{ @@ -140,13 +140,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -168,13 +167,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -185,6 +183,7 @@ func TestSignalControllerEventFilter(t *testing.T) { }, false, }, + { "Different hostname", crev.UpdateEvent{ @@ -207,13 +206,12 @@ func TestSignalControllerEventFilter(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.2.3", - "url": "https://www.google.com/download.tar.gz", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "thisisthesha" - } + "id": 123, + "k0supdate": { + "version": "v1.2.3", + "url": "https://www.google.com/download.tar.gz", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "thisisthesha" } } } @@ -251,13 +249,12 @@ func TestSignalControllerSameVersion(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.23.3+k0s.0", - "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" - } + "id": 123, + "k0supdate": { + "version": "v1.23.3+k0s.0", + "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" } } } @@ -356,13 +353,12 @@ func TestSignalControllerNewVersion(t *testing.T) { "planId":"abc123", "created":"now", "command": { - "update": { - "k0s": { - "version": "v1.23.3+k0s.0", - "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", - "timestamp": "2021-10-20T19:06:56Z", - "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" - } + "id": 123, + "k0supdate": { + "version": "v1.23.3+k0s.0", + "url": "https://github.com/k0sproject/k0s/releases/download/v1.23.3%2Bk0s.0/k0s-v1.23.3+k0s.0-amd64", + "timestamp": "2021-10-20T19:06:56Z", + "sha256": "aa170c7fa0ea3fe1194eaec6a18964543e1e139eab1cfbbbafec7f357fb1679d" } } } @@ -463,12 +459,11 @@ func TestCheckExpiredInvalid(t *testing.T) { &apsigv2.SignalData{ Created: "now", Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{ - Version: "v1.2.3", - URL: "https://www.google.com/download.tar.gz", - Sha256: "thisisthesha", - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{ + Version: "v1.2.3", + URL: "https://www.google.com/download.tar.gz", + Sha256: "thisisthesha", }, }, Status: &apsigv2.Status{ @@ -487,12 +482,11 @@ func TestCheckExpiredInvalid(t *testing.T) { &apsigv2.SignalData{ Created: "now", Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{ - Version: "v1.2.3", - URL: "https://www.google.com/download.tar.gz", - Sha256: "thisisthesha", - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{ + Version: "v1.2.3", + URL: "https://www.google.com/download.tar.gz", + Sha256: "thisisthesha", }, }, Status: &apsigv2.Status{ @@ -511,12 +505,11 @@ func TestCheckExpiredInvalid(t *testing.T) { &apsigv2.SignalData{ Created: "now", Command: apsigv2.Command{ - Update: &apsigv2.CommandUpdateItem{ - K0s: &apsigv2.CommandUpdateItemK0s{ - Version: "v1.2.3", - URL: "https://www.google.com/download.tar.gz", - Sha256: "thisisthesha", - }, + ID: new(int), + K0sUpdate: &apsigv2.CommandK0sUpdate{ + Version: "v1.2.3", + URL: "https://www.google.com/download.tar.gz", + Sha256: "thisisthesha", }, }, Status: &apsigv2.Status{ diff --git a/autopilot/pkg/signaling/v2/signaling_v2.go b/autopilot/pkg/signaling/v2/signaling_v2.go index de777f661c58..126e3e4bbb68 100644 --- a/autopilot/pkg/signaling/v2/signaling_v2.go +++ b/autopilot/pkg/signaling/v2/signaling_v2.go @@ -68,7 +68,6 @@ var _ signaling.Validator = (*SignalData)(nil) func (s SignalData) Validate() error { validate := validator.New() validate.RegisterStructValidation(validateCommand, Command{}) - validate.RegisterStructValidation(validateCommandUpdateItem, CommandUpdateItem{}) return validate.Struct(s) } @@ -135,48 +134,33 @@ func IsSignalingPresent(m map[string]string) bool { // Command contains all of the at-most-one commands that can be used to control // an `autopilot` operation. Currently only `update` is supported. type Command struct { - Update *CommandUpdateItem `json:"update" validate:"required"` + ID *int `json:"id" validate:"required"` + K0sUpdate *CommandK0sUpdate `json:"k0supdate,omitempty"` + AirgapUpdate *CommandAirgapUpdate `json:"airgapupdate,omitempty"` } -// CommandUpdateItem contains all of the at-most-one update items that can be used -// as part of an `autopilot` update. -type CommandUpdateItem struct { - K0s *CommandUpdateItemK0s `json:"k0s,omitempty"` - Airgap *CommandUpdateItemAirgap `json:"airgap,omitempty"` -} - -// CommandUpdateItemK0s describes what an update to `k0s` is. -type CommandUpdateItemK0s struct { +// CommandK0sUpdate describes what an update to `k0s` is. +type CommandK0sUpdate struct { URL string `json:"url" validate:"required,url"` Version string `json:"version" validate:"required"` Sha256 string `json:"sha256,omitempty"` } -// CommandUpdateItemAirgap describes what an update to `airgap` is. -type CommandUpdateItemAirgap struct { +// CommandAirgapUpdate describes what an update to `airgap` is. +type CommandAirgapUpdate struct { URL string `json:"url" validate:"required,url"` Version string `json:"version" validate:"required"` Sha256 string `json:"sha256,omitempty"` } -// validateCommand ensures that a `Command` contains at-most-one of the following fields: `Update` +// validateCommand ensures that a `Command` contains at-most-one of +// the following fields: `K0sUpdate`, `AirgapUpdate`. func validateCommand(sl validator.StructLevel) { - command := sl.Current().Interface().(Command) - - // Provide at-most-one semantics, ensuring that only one field is defined. - if command.Update == nil { - sl.ReportError(reflect.ValueOf(command.Update), "Update", "update", "atmostone", "") - } -} - -// validateCommandUpdateItem ensures that a `CommandUpdateItem` contains at-most-one of -// the following fields: `K0s`. -func validateCommandUpdateItem(sl validator.StructLevel) { - cui := sl.Current().Interface().(CommandUpdateItem) + cui := sl.Current().Interface().(Command) // Provide at-most-one semantics, ensuring that only one field is defined. - if (cui.K0s == nil && cui.Airgap == nil) || (cui.K0s != nil && cui.Airgap != nil) { - sl.ReportError(reflect.ValueOf(cui.K0s), "K0s", "k0s", "atmostone", "") - sl.ReportError(reflect.ValueOf(cui.Airgap), "Airgap", "airgap", "atmostone", "") + if (cui.K0sUpdate == nil && cui.AirgapUpdate == nil) || (cui.K0sUpdate != nil && cui.AirgapUpdate != nil) { + sl.ReportError(reflect.ValueOf(cui.K0sUpdate), "K0sUpdate", "k0supdate", "atmostone", "") + sl.ReportError(reflect.ValueOf(cui.AirgapUpdate), "AirgapUpdate", "airgapupdate", "atmostone", "") } } diff --git a/autopilot/pkg/signaling/v2/signaling_v2_test.go b/autopilot/pkg/signaling/v2/signaling_v2_test.go index 600b26559e99..24031fd81430 100644 --- a/autopilot/pkg/signaling/v2/signaling_v2_test.go +++ b/autopilot/pkg/signaling/v2/signaling_v2_test.go @@ -43,11 +43,10 @@ func TestSignalValid(t *testing.T) { // TestSignalDataValid tests the validation of the direct fields in `SignalData`. func TestSignalDataValid(t *testing.T) { commandK0s := Command{ - Update: &CommandUpdateItem{ - K0s: &CommandUpdateItemK0s{ - URL: "https://foo.bar.baz", - Version: "v1.2.3", - }, + ID: new(int), + K0sUpdate: &CommandK0sUpdate{ + URL: "https://foo.bar.baz", + Version: "v1.2.3", }, } @@ -80,12 +79,11 @@ func TestSignalDataUpdateK0sValid(t *testing.T) { return SignalData{ Created: "now", Command: Command{ - Update: &CommandUpdateItem{ - K0s: &CommandUpdateItemK0s{ - URL: url, - Version: version, - Sha256: sha256, - }, + ID: new(int), + K0sUpdate: &CommandK0sUpdate{ + URL: url, + Version: version, + Sha256: sha256, }, }, Status: &Status{ @@ -125,7 +123,8 @@ func TestSignalDataUpdateK0sValid(t *testing.T) { SignalData{ Created: "now", Command: Command{ - Update: &CommandUpdateItem{}, + ID: new(int), + K0sUpdate: &CommandK0sUpdate{}, }, }, false, @@ -144,12 +143,11 @@ func TestMarshaling(t *testing.T) { signalData1 := SignalData{ Created: "now", Command: Command{ - Update: &CommandUpdateItem{ - K0s: &CommandUpdateItemK0s{ - URL: "https://foo.bar.baz", - Version: "v1.2.3", - Sha256: "deadbeef", - }, + ID: new(int), + K0sUpdate: &CommandK0sUpdate{ + URL: "https://foo.bar.baz", + Version: "v1.2.3", + Sha256: "deadbeef", }, }, Status: &Status{