package examples import ( _ "embed" "time" "edge-infra.dev/pkg/edge/rollouts" ) const ( samplePlanID = "abcde-12345" sampleGraphID = "fghij-67890" ) //go:embed simple-graph.json var SampleGraphJSON []byte //go:embed simple-plan.json var SamplePlanJSON []byte type sampleTimer struct { fakeTime time.Time } func (t *sampleTimer) Now() time.Time { return t.fakeTime } var timer = &sampleTimer{fakeTime: time.Now()} func GetSampleGraphFromJSON() *rollouts.RolloutGraph { graph, _ := rollouts.NewRolloutGraphFromJSON(SampleGraphJSON) return graph } func GetSamplePlanFromJSON() rollouts.RolloutPlan { plan, _ := rollouts.NewRolloutPlanFromJSON(SamplePlanJSON) return plan } // TODO(dk185217): Either move to _test.go or remove. Examples for human use and developers wont // be creating graph entity structs etc etc func CreateSamplePlan() rollouts.RolloutPlan { plan := rollouts.RolloutPlan{ ID: samplePlanID, Name: "A sample plan", Description: "A sample rollout plan that deploys store version 0.21 to pilot stores, then stage east and west, with a final approval to general us stores", Nodes: rollouts.NodeMap{}, } targetGroup1 := rollouts.NewTargetGroup( "targetGroup1", // the key of the node "pilot", // selector label that will match cluster IDs "store", // artifact name "0.21", // the desired version of the artifact ) plan.Nodes.AddNode(targetGroup1) timerGate1 := rollouts.NewTimerGate( "timerGate1", time.Now(), // the start time of the timer time.Second*600, // the duration of the timer timer, // a TimeSource ) plan.Nodes.AddNode(timerGate1) targetGroup2 := rollouts.NewTargetGroup( "targetGroup2", "stage:east", "store", "0.21", ) plan.Nodes.AddNode(targetGroup2) targetGroup3 := rollouts.NewTargetGroup( "targetGroup3", // the key of the node "stage:west", // selector "store", // artifact name "0.21", // the desired version of the artifact ) plan.Nodes.AddNode(targetGroup3) approvalGate1 := rollouts.NewApprovalGate("approvalGate1") plan.Nodes.AddNode(approvalGate1) targetGroup4 := rollouts.NewTargetGroup( "targetGroup4", // the key of the node "general:us", // selector "store", // artifact name "0.21", // the desired version of the artifact ) // connect edges // // targetGroup2 // targetGroup1 -> timerGate1 -> -> approvalGate1 -> targetGroup4 // targetGroup3 plan.Edges = rollouts.ConnectEdge(targetGroup1, timerGate1, plan.Edges) plan.Edges = rollouts.ConnectEdge(timerGate1, targetGroup2, plan.Edges) plan.Edges = rollouts.ConnectEdge(timerGate1, targetGroup3, plan.Edges) plan.Edges = rollouts.ConnectEdge(targetGroup2, approvalGate1, plan.Edges) plan.Edges = rollouts.ConnectEdge(targetGroup3, approvalGate1, plan.Edges) plan.Edges = rollouts.ConnectEdge(approvalGate1, targetGroup4, plan.Edges) return plan } func CreateSampleGraph(plan rollouts.RolloutPlan) *rollouts.RolloutGraph { // add a custom time source to the graph customTimeSource := &sampleTimer{} opts := []rollouts.Option{rollouts.WithTimeSource(customTimeSource)} return rollouts.NewRolloutGraph(plan, opts...) }