Skip to content

Commit

Permalink
fix: Also take clusterId into account in GetKluctlDeployment
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Aug 3, 2023
1 parent e949041 commit 97b0923
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 5 additions & 1 deletion pkg/results/result-store-secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,11 @@ func (s *ResultStoreSecrets) WatchKluctlDeployments() (<-chan WatchKluctlDeploym
return ch, cancel, nil
}

func (s *ResultStoreSecrets) GetKluctlDeployment(name string, namespace string) (*kluctlv1.KluctlDeployment, error) {
func (s *ResultStoreSecrets) GetKluctlDeployment(clusterId string, name string, namespace string) (*kluctlv1.KluctlDeployment, error) {
if s.clusterId != clusterId {
return nil, fmt.Errorf("clusterId does not match")
}

var k kluctlv1.KluctlDeployment
err := s.cache.Get(s.ctx, client.ObjectKey{Name: name, Namespace: namespace}, &k)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/results/result-store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ResultStore interface {

ListKluctlDeployments() ([]kluctlv1.KluctlDeployment, error)
WatchKluctlDeployments() (<-chan WatchKluctlDeploymentEvent, context.CancelFunc, error)
GetKluctlDeployment(name string, namespace string) (*kluctlv1.KluctlDeployment, error)
GetKluctlDeployment(clusterId string, name string, namespace string) (*kluctlv1.KluctlDeployment, error)
}

func FilterProject(x result.ProjectKey, filter *result.ProjectKey) bool {
Expand Down
20 changes: 9 additions & 11 deletions pkg/results/results-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type validateSummaryEntry struct {
}

type kluctlDeploymentEntry struct {
store ResultStore
deployment *kluctlv1.KluctlDeployment
store ResultStore
event WatchKluctlDeploymentEvent
}

type commandResultWatchEntry struct {
Expand Down Expand Up @@ -229,8 +229,8 @@ func (rc *ResultsCollector) handleKluctlDeploymentUpdate(store ResultStore, even
}
} else {
rc.kluctlDeployments[event.Deployment.UID] = kluctlDeploymentEntry{
store: store,
deployment: event.Deployment,
store: store,
event: event,
}
}

Expand Down Expand Up @@ -396,7 +396,7 @@ func (rc *ResultsCollector) ListKluctlDeployments() ([]kluctlv1.KluctlDeployment
defer rc.mutex.Unlock()
ret := make([]kluctlv1.KluctlDeployment, 0, len(rc.commandResultSummaries))
for _, x := range rc.kluctlDeployments {
ret = append(ret, *x.deployment)
ret = append(ret, *x.event.Deployment)
}
return ret, nil
}
Expand All @@ -420,9 +420,7 @@ func (rc *ResultsCollector) WatchKluctlDeployments() (<-chan WatchKluctlDeployme
}

for _, e := range rc.kluctlDeployments {
w.ch <- WatchKluctlDeploymentEvent{
Deployment: e.deployment,
}
w.ch <- e.event
}

rc.kluctlDeploymentWatches = append(rc.kluctlDeploymentWatches, w)
Expand All @@ -444,13 +442,13 @@ func (rc *ResultsCollector) WatchKluctlDeployments() (<-chan WatchKluctlDeployme
return w.ch, cancel, nil
}

func (rc *ResultsCollector) GetKluctlDeployment(name string, namespace string) (*kluctlv1.KluctlDeployment, error) {
func (rc *ResultsCollector) GetKluctlDeployment(clusterId string, name string, namespace string) (*kluctlv1.KluctlDeployment, error) {
rc.mutex.Lock()
defer rc.mutex.Unlock()

for _, kd := range rc.kluctlDeployments {
if kd.deployment.Name == name && kd.deployment.Namespace == namespace {
return kd.deployment, nil
if kd.event.ClusterId == clusterId && kd.event.Deployment.Name == name && kd.event.Deployment.Namespace == namespace {
return kd.event.Deployment, nil
}
}
return nil, nil
Expand Down

0 comments on commit 97b0923

Please sign in to comment.