4
4
"context"
5
5
"fmt"
6
6
"sort"
7
- "strings"
8
7
"time"
9
8
10
9
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
@@ -131,7 +130,7 @@ func WaitForInstallation(ctx context.Context, cli client.Client, writer *spinner
131
130
lastInstall := installs [0 ]
132
131
133
132
if writer != nil {
134
- writeStatusMessage (writer , lastInstall . Status )
133
+ writeStatusMessage (writer , lastInstall )
135
134
}
136
135
137
136
// check the status of the installation
@@ -148,27 +147,34 @@ func WaitForInstallation(ctx context.Context, cli client.Client, writer *spinner
148
147
return nil
149
148
}
150
149
151
- func writeStatusMessage (writer * spinner.MessageWriter , status embeddedclusterv1beta1.InstallationStatus ) {
152
- if status .State != embeddedclusterv1beta1 .InstallationStatePendingChartCreation {
153
- writer .Infof ("Waiting for additional components to be ready: %s" , status .Reason )
150
+ func writeStatusMessage (writer * spinner.MessageWriter , install embeddedclusterv1beta1.Installation ) {
151
+ if install .Status .State != embeddedclusterv1beta1 .InstallationStatePendingChartCreation {
154
152
return
155
153
}
156
154
157
- chartNames := ""
158
- if len (status .PendingCharts ) == 0 {
155
+ if install .Spec .Config == nil || install .Spec .Config .Extensions .Helm == nil {
159
156
return
160
- } else if len (status .PendingCharts ) == 1 {
161
- // A
162
- chartNames = status .PendingCharts [0 ]
163
- } else if len (status .PendingCharts ) == 2 {
164
- // A and B
165
- chartNames = strings .Join (status .PendingCharts , " and " )
166
- } else {
167
- // A, B, and C
168
- chartNames = strings .Join (status .PendingCharts [:len (status .PendingCharts )- 1 ], ", " ) + " and " + status .PendingCharts [len (status .PendingCharts )- 1 ]
157
+ }
158
+ numDesiredCharts := len (install .Spec .Config .Extensions .Helm .Charts )
159
+
160
+ pendingChartsMap := map [string ]struct {}{}
161
+ for _ , chartName := range install .Status .PendingCharts {
162
+ pendingChartsMap [chartName ] = struct {}{}
169
163
}
170
164
171
- writer .Infof ("Waiting for additional components %s to be ready" , chartNames )
165
+ numPendingCharts := 0
166
+ for _ , ch := range install .Spec .Config .Extensions .Helm .Charts {
167
+ if _ , ok := pendingChartsMap [ch .Name ]; ok {
168
+ numPendingCharts ++
169
+ }
170
+ }
171
+ numCompletedCharts := numDesiredCharts - numPendingCharts
172
+
173
+ if numCompletedCharts < numDesiredCharts {
174
+ writer .Infof ("Waiting for additional components to be ready (%d/%d)" , numCompletedCharts , numDesiredCharts )
175
+ } else {
176
+ writer .Infof ("Finalizing additional components" )
177
+ }
172
178
}
173
179
174
180
func IsNamespaceReady (ctx context.Context , cli client.Client , ns string ) (bool , error ) {
0 commit comments