package internal import ( "fmt" "edge-infra.dev/pkg/edge/rollouts" "edge-infra.dev/pkg/edge/rollouts/examples" ) const ( ExamplePlanID = "my-example-plan" ExampleRolloutID = "my-example-rollout" ExampleClusterID = "my-cluster-id" ExampleBannerID = "my-banner-id" StoreArtifactName = "store" ) type BannerByteGraphs map[string][]byte type BannerByteGraphStore map[string]BannerByteGraphs type BannerGraphs map[string]*rollouts.RolloutGraph type BannerGraphStore map[string]BannerGraphs func NewBannerGraphStore(graphs BannerByteGraphStore) (BannerGraphStore, error) { bgs := BannerGraphStore{} if graphs == nil { return bgs, nil } for bannerID, bGraphs := range graphs { bg := BannerGraphs{} for rolloutID, graphBytes := range bGraphs { g, err := rollouts.NewRolloutGraphFromJSON(graphBytes) if err != nil { return bgs, err } bg[rolloutID] = g } bgs[bannerID] = bg } return bgs, nil } var ExampleBannerByteGraphStore = BannerByteGraphStore{ ExampleBannerID: BannerByteGraphs{ ExampleRolloutID: examples.SampleGraphJSON, }, } type BannerBytePlans map[string][]byte type BannerBytePlanStore map[string]BannerBytePlans type BannerPlans map[string]rollouts.RolloutPlan type BannerPlanStore map[string]BannerPlans func NewBannerPlanStore(plans BannerBytePlanStore) (BannerPlanStore, error) { bps := BannerPlanStore{} if plans == nil { return bps, nil } for bannerID, bPlans := range plans { bp := BannerPlans{} for rolloutID, planBytes := range bPlans { p, err := rollouts.NewRolloutPlanFromJSON(planBytes) if err != nil { return bps, err } bp[rolloutID] = p } bps[bannerID] = bp } return bps, nil } var ExampleBannerBytePlanStore = BannerBytePlanStore{ ExampleBannerID: BannerBytePlans{ ExamplePlanID: examples.SamplePlanJSON, }, } type LabelStore map[string][]string func NewExampleLabelStore() LabelStore { return LabelStore{ "dev": {"dev0", "dev1", "dev2"}, "staging:east": {"stage0-east", "stage1-east"}, "staging:west": {"stage0-west", "stage1-west"}, "prod:us": {"prod0-us"}, } } type TargetGroupStateStore struct { clusterVersions map[string]ClusterVersionState } type VersionState struct { Ready bool Version string } func (vs *VersionState) String() string { return fmt.Sprintf("Ready: %t, Version: %s", vs.Ready, vs.Version) } type ClusterVersionState map[string]*VersionState func NewExampleTGStore() TargetGroupStateStore { return TargetGroupStateStore{ clusterVersions: map[string]ClusterVersionState{ "dev0": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "dev1": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "dev2": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "stage0-east": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "stage1-east": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "stage0-west": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "stage1-west": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, "prod0-us": {StoreArtifactName: &VersionState{Ready: false, Version: "0.20"}}, }, } } type ArtifactVersionStore map[string]string func NewExampleAVStore() ArtifactVersionStore { return ArtifactVersionStore{"store": "0.20"} } type ApprovalGateStore map[rollouts.NodeKey]rollouts.GateApproval func NewExampleAGStore() ApprovalGateStore { return ApprovalGateStore{"ag1": rollouts.GatePending} }