package internal import ( "fmt" "edge-infra.dev/pkg/edge/rollouts" ) func NewExampleInMemStore() *InMemStore { graphStore, err := NewBannerGraphStore(ExampleBannerByteGraphStore) fmt.Printf("graphStore address: %p\n", graphStore) if err != nil { panic(err) } fmt.Printf("tg1 address: %p\n", graphStore[ExampleBannerID][ExampleRolloutID].Nodes["tg1"]) planStore, err := NewBannerPlanStore(ExampleBannerBytePlanStore) if err != nil { panic(err) } return &InMemStore{ PlanStore: planStore, GraphStore: graphStore, LabelStore: NewExampleLabelStore(), TargetGroupStateStore: NewExampleTGStore(), ApprovalGateStore: NewExampleAGStore(), ArtifactVersionStore: NewExampleAVStore(), } } type InMemStore struct { GraphStore BannerGraphStore PlanStore BannerPlanStore LabelStore LabelStore TargetGroupStateStore TargetGroupStateStore ApprovalGateStore ApprovalGateStore ArtifactVersionStore ArtifactVersionStore } func (s *InMemStore) GetTargetGroupVersionStates(artifactName string, clusterMatches rollouts.MatchResult) ([]*VersionState, error) { tgs := []*VersionState{} for _, match := range clusterMatches.Matches { if artifact, found := s.TargetGroupStateStore.clusterVersions[match][artifactName]; found { fmt.Printf("version state address: %p\n", artifact) tgs = append(tgs, artifact) } } if len(tgs) == 0 { return nil, fmt.Errorf("no matches found for clusters [%s]", clusterMatches.Matches) } return tgs, nil } func (s *InMemStore) GetClusterLabelMatches(selector string) (rollouts.MatchResult, error) { result := rollouts.MatchResult{ Matches: []string{}, } var clusterIDs []string if foundClusterIDs, found := s.LabelStore[selector]; found { clusterIDs = append(clusterIDs, foundClusterIDs...) result.Matches = append(result.Matches, clusterIDs...) } return result, nil } func (s *InMemStore) ApplyClusterArtifactVersions(artifactName string, artifactVersion string, clusterMatches rollouts.MatchResult) error { for _, match := range clusterMatches.Matches { if state, found := s.TargetGroupStateStore.clusterVersions[match][artifactName]; !found { fmt.Printf("didn't find artifact %s for %s. setting to pending\n", artifactName, match) s.TargetGroupStateStore.clusterVersions[match][artifactName] = &VersionState{Version: artifactVersion} } else { fmt.Printf("found %s for %s. applying\n", artifactName, match) // s.targetGroupStateStore.clusterVersions[match][artifactName] = &VersionState{Version: artifactVersion} state.Version = artifactVersion } } return nil } func (s *InMemStore) SetClusterArtifactReady(artifactName string, clusterMatches rollouts.MatchResult) { for _, clusterID := range clusterMatches.Matches { if clusterVersionState, clusterFound := s.TargetGroupStateStore.clusterVersions[clusterID]; clusterFound { if versionState, artifactFound := clusterVersionState[artifactName]; artifactFound { versionState.Ready = true } } } } func (s *InMemStore) GetApprovalGateStatus(ag *rollouts.ApprovalGate) (rollouts.GateApproval, error) { storeGateStatus, found := s.ApprovalGateStore[ag.GetKey()] if !found { return rollouts.GatePending, fmt.Errorf("gate %s not found", ag.GetKey()) } return storeGateStatus, nil } func (s *InMemStore) OpenApprovalGate(agKey rollouts.NodeKey) error { _, found := s.ApprovalGateStore[agKey] if !found { return fmt.Errorf("gate %s not found", agKey) } s.ApprovalGateStore[agKey] = rollouts.GateApproved return nil }