From 854ab1c629e1c8a74aefbef94945982992b3a930 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Thu, 28 Sep 2023 13:45:43 +0100 Subject: [PATCH] (feat): Warning users about create OSTree static deltas before rolling out waves Signed-off-by: Camila Macedo --- client/foundries.go | 5 +++++ subcommands/waves/init.go | 32 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/client/foundries.go b/client/foundries.go index c2b60497..6eadad8e 100644 --- a/client/foundries.go +++ b/client/foundries.go @@ -277,6 +277,10 @@ type ProjectTrigger struct { Id int `json:"id,omitempty"` Secrets []ProjectSecret `json:"secrets"` } +type DeltaStats struct { + Sha256 string `json:"sha256"` + Size int `json:"size"` +} type TufCustom struct { HardwareIds []string `json:"hardwareIds,omitempty"` @@ -286,6 +290,7 @@ type TufCustom struct { ComposeApps map[string]ComposeApp `json:"docker_compose_apps,omitempty"` Name string `json:"name,omitempty"` ContainersSha string `json:"containers-sha,omitempty"` + DeltaStats *DeltaStats `json:"delta-stats,omitempty"` LmpManifestSha string `json:"lmp-manifest-sha,omitempty"` OverridesSha string `json:"meta-subscriber-overrides-sha,omitempty"` Uri string `json:"uri,omitempty"` diff --git a/subcommands/waves/init.go b/subcommands/waves/init.go index 0bab2f07..e764aa36 100644 --- a/subcommands/waves/init.go +++ b/subcommands/waves/init.go @@ -27,7 +27,12 @@ func init() { This command only initializes a wave, but does not provision its updates to devices. Use a "fioctl wave rollout " to trigger updates of this wave to a device group. Use a "fioctl wave complete " to update all devices (make it globally available). -Use a "fioctl wave cancel to cancel a wave (make it no longer available).`, +Use a "fioctl wave cancel to cancel a wave (make it no longer available). + +We recommend that you generate static deltas for your production targets to optimize +the size of the update. Please, consider generating a static delta for targets using: +$ fioctl targets static-deltas. +`, Run: doInitWave, Args: cobra.ExactArgs(3), Example: ` @@ -145,6 +150,31 @@ func doInitWave(cmd *cobra.Command, args []string) { } else { subcommands.DieNotNil(api.FactoryCreateWave(factory, &wave), "Failed to create a wave") } + + if !hasStaticDelta(new_targets) { + + fmt.Print(` +WARNING: You created a wave for a target version without static deltas. + +We recommend that you generate static deltas for your production targets to optimize +the size of the update. Please, consider generating a static delta for targets using: +$ fioctl targets static-deltas. + +You can then cancel this wave and create a new one for a target with a static delta. +`) + + } +} + +func hasStaticDelta(new_targets tuf.Files) bool { + for _, file := range new_targets { + custom, err := api.TargetCustom(file) + subcommands.DieNotNil(err) + if custom.DeltaStats != nil { + return true + } + } + return false } func pruneTargets(currentTargets *client.AtsTargetsMeta, versions []string) client.AtsTargetsMeta {