From f65372b90462dcf08677baecdc90e31bdb367b2b Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Wed, 3 Aug 2022 12:57:00 +0000 Subject: [PATCH] Allow easier creation of DelegatedStatusReader with custom status readers --- pkg/kstatus/polling/statusreaders/default.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/kstatus/polling/statusreaders/default.go b/pkg/kstatus/polling/statusreaders/default.go index 48de1b9f..a5f61f18 100644 --- a/pkg/kstatus/polling/statusreaders/default.go +++ b/pkg/kstatus/polling/statusreaders/default.go @@ -20,19 +20,27 @@ import ( // statusreaders to cover all built-in Kubernetes resources and other CRDs that // follow known status conventions. func NewDefaultStatusReader(mapper meta.RESTMapper) engine.StatusReader { + return NewStatusReader(mapper) +} + +// NewStatusReader returns a DelegatingStatusReader that includes the statusreaders +// for the build-in Kubernetes resources and also any provided custom status readers. +func NewStatusReader(mapper meta.RESTMapper, statusReaders ...engine.StatusReader) engine.StatusReader { defaultStatusReader := NewGenericStatusReader(mapper, status.Compute) replicaSetStatusReader := NewReplicaSetStatusReader(mapper, defaultStatusReader) deploymentStatusReader := NewDeploymentResourceReader(mapper, replicaSetStatusReader) statefulSetStatusReader := NewStatefulSetResourceReader(mapper, defaultStatusReader) + statusReaders = append(statusReaders, + deploymentStatusReader, + statefulSetStatusReader, + replicaSetStatusReader, + defaultStatusReader, + ) + return &DelegatingStatusReader{ - StatusReaders: []engine.StatusReader{ - deploymentStatusReader, - statefulSetStatusReader, - replicaSetStatusReader, - defaultStatusReader, - }, + StatusReaders: statusReaders, } }