Skip to content

Commit 4c84fc6

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

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

pkg/streamline/applier/applier.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,60 @@ 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, err = in.appendUnsyncedResources(service.ID, componentList, resources)
194+
192195
return componentList, serviceErrorList, nil
193196
}
194197

198+
func (in *Applier) appendUnsyncedResources(serviceId string, components []client.ComponentAttributes, resources []unstructured.Unstructured) ([]client.ComponentAttributes, error) {
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+
hooks, err := in.store.GetHookComponents(serviceId)
208+
if err != nil {
209+
return nil, err
210+
}
211+
212+
// Create a map of hooks for an easy lookup.
213+
keyToHookComponent := make(map[smcommon.Key]smcommon.HookComponent)
214+
for _, hook := range hooks {
215+
keyToHookComponent[hook.StoreKey().Key()] = hook
216+
}
217+
218+
for _, resource := range resources {
219+
key := smcommon.NewStoreKeyFromUnstructured(resource).Key()
220+
221+
if !keys.Has(key) {
222+
// If a resource has any delete policy, check if it was already deleted.
223+
// If it was deleted, then do not include it in the result.
224+
deletePolicies := smcommon.ParseHookDeletePolicy(resource)
225+
hook, ok := keyToHookComponent[key]
226+
if len(deletePolicies) > 0 && ok && hook.HasDesiredState(deletePolicies) {
227+
continue
228+
}
229+
230+
gvk := resource.GroupVersionKind()
231+
result = append(result, client.ComponentAttributes{
232+
Group: gvk.Group,
233+
Version: gvk.Version,
234+
Kind: gvk.Kind,
235+
Name: resource.GetName(),
236+
Namespace: resource.GetNamespace(),
237+
Synced: false,
238+
State: lo.ToPtr(client.ComponentStatePending),
239+
})
240+
}
241+
}
242+
243+
return result, nil
244+
}
245+
195246
func (in *Applier) Destroy(ctx context.Context, serviceID string) ([]client.ComponentAttributes, error) {
196247
deleted := 0
197248
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)