Skip to content

Commit bc9653c

Browse files
committed
send unsynced resources with status updates
1 parent 077fab2 commit bc9653c

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

pkg/streamline/applier/applier.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,43 @@ func (in *Applier) Apply(ctx context.Context,
189189
componentList[idx].Children = lo.ToSlicePtr(children)
190190
}
191191

192+
// Append unsynced resources to the component list so all of them will be visible in the UI.
193+
componentList = in.appendUnsyncedResources(componentList, resources)
194+
192195
return componentList, serviceErrorList, nil
193196
}
194197

198+
func (in *Applier) appendUnsyncedResources(components []client.ComponentAttributes, resources []unstructured.Unstructured) []client.ComponentAttributes {
199+
result := make([]client.ComponentAttributes, 0)
200+
keys := containers.NewSet[smcommon.Key]()
201+
202+
for _, component := range components {
203+
result = append(result, component)
204+
keys.Add(smcommon.NewStoreKeyFromComponentAttributes(component).Key())
205+
}
206+
207+
// TODO: Skip components that were deleted with deletion policy.
208+
209+
for _, resource := range resources {
210+
if !keys.Has(smcommon.NewStoreKeyFromUnstructured(resource).Key()) {
211+
gvk := resource.GroupVersionKind()
212+
result = append(result, client.ComponentAttributes{
213+
Group: gvk.Group,
214+
Version: gvk.Version,
215+
Kind: gvk.Kind,
216+
Name: resource.GetName(),
217+
Namespace: resource.GetNamespace(),
218+
219+
// TODO: Set following fields based on resource/phase processing status.
220+
Synced: false,
221+
State: nil,
222+
})
223+
}
224+
}
225+
226+
return result
227+
}
228+
195229
func (in *Applier) Destroy(ctx context.Context, serviceID string) ([]client.ComponentAttributes, error) {
196230
deleted := 0
197231
deleteFilterFunc, err := in.getDeleteFilterFunc(serviceID)

pkg/streamline/common/key.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"fmt"
55

6+
"github.com/pluralsh/console/go/client"
67
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
78
"k8s.io/apimachinery/pkg/runtime/schema"
89
)
@@ -54,3 +55,11 @@ func (in StoreKey) ReplaceGroup(group string) StoreKey {
5455
func NewStoreKeyFromUnstructured(u unstructured.Unstructured) StoreKey {
5556
return StoreKey{GVK: u.GroupVersionKind(), Namespace: u.GetNamespace(), Name: u.GetName()}
5657
}
58+
59+
func NewStoreKeyFromComponentAttributes(a client.ComponentAttributes) StoreKey {
60+
return StoreKey{
61+
GVK: schema.GroupVersionKind{Group: a.Group, Version: a.Version, Kind: a.Kind},
62+
Namespace: a.Namespace,
63+
Name: a.Name,
64+
}
65+
}

pkg/streamline/status_synchronizer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (in *StatusSynchronizer) UpdateServiceComponents(serviceId string, componen
5656
return nil
5757
}
5858

59+
// TODO: Sync statuses of components that were not processed yet.
60+
5961
if err = in.client.UpdateComponents(serviceId, "", nil, components, nil, nil); err != nil {
6062
return err
6163
}

pkg/streamline/store/db_queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
transient_manifest_sha TEXT,
2222
apply_sha TEXT,
2323
server_sha TEXT,
24-
manifest BOOLEAN DEFAULT 0
24+
manifest BOOLEAN DEFAULT 0 -- Indicates if the component was created from an original manifest set of a service
2525
);
2626
CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_component ON component("group", version, kind, namespace, name);
2727
CREATE INDEX IF NOT EXISTS idx_parent ON component(parent_uid);

0 commit comments

Comments
 (0)