Skip to content

Commit

Permalink
chore: unexport table printer internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Feb 15, 2022
1 parent 026b9cc commit 5d23501
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pkg/apply/info/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Helper interface {
BuildInfo(obj *unstructured.Unstructured) (*resource.Info, error)
}

func NewHelper(mapper meta.RESTMapper, unstructuredClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)) *helper {
func NewHelper(mapper meta.RESTMapper, unstructuredClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)) Helper {
return &helper{
mapper: mapper,
unstructuredClientForMapping: unstructuredClientForMapping,
Expand Down
60 changes: 30 additions & 30 deletions pkg/printers/table/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

const InvalidStatus status.Status = "Invalid"

func newResourceStateCollector(resourceGroups []event.ActionGroup) *ResourceStateCollector {
resourceInfos := make(map[object.ObjMetadata]*ResourceInfo)
func newResourceStateCollector(resourceGroups []event.ActionGroup) *resourceStateCollector {
resourceInfos := make(map[object.ObjMetadata]*resourceInfo)
for _, group := range resourceGroups {
action := group.Action
// Keep the action that describes the operation for the resource
Expand All @@ -30,7 +30,7 @@ func newResourceStateCollector(resourceGroups []event.ActionGroup) *ResourceStat
continue
}
for _, identifier := range group.Identifiers {
resourceInfos[identifier] = &ResourceInfo{
resourceInfos[identifier] = &resourceInfo{
identifier: identifier,
resourceStatus: &pe.ResourceStatus{
Identifier: identifier,
Expand All @@ -40,31 +40,31 @@ func newResourceStateCollector(resourceGroups []event.ActionGroup) *ResourceStat
}
}
}
return &ResourceStateCollector{
return &resourceStateCollector{
resourceInfos: resourceInfos,
}
}

// ResourceStateCollector consumes the events from the applier
// resourceStateCollector consumes the events from the applier
// eventChannel and keeps track of the latest state for all resources.
// It also provides functionality for fetching the latest seen
// state and return it in format that can be used by the
// BaseTablePrinter.
type ResourceStateCollector struct {
type resourceStateCollector struct {
mux sync.RWMutex

// resourceInfos contains a mapping from the unique
// resource identifier to a ResourceInfo object that captures
// the latest state for the given resource.
resourceInfos map[object.ObjMetadata]*ResourceInfo
resourceInfos map[object.ObjMetadata]*resourceInfo

err error
}

// ResourceInfo captures the latest seen state of a single resource.
// resourceInfo captures the latest seen state of a single resource.
// This is used for top-level resources that have a ResourceAction
// associated with them.
type ResourceInfo struct {
type resourceInfo struct {
// identifier contains the information that identifies a
// single resource.
identifier object.ObjMetadata
Expand Down Expand Up @@ -100,55 +100,55 @@ type ResourceInfo struct {
}

// Identifier returns the identifier for the given resource.
func (r *ResourceInfo) Identifier() object.ObjMetadata {
func (r *resourceInfo) Identifier() object.ObjMetadata {
return r.identifier
}

// ResourceStatus returns the latest seen status for the
// resource.
func (r *ResourceInfo) ResourceStatus() *pe.ResourceStatus {
func (r *resourceInfo) ResourceStatus() *pe.ResourceStatus {
return r.resourceStatus
}

// SubResources returns a slice of Resource which contains
// any resources created and managed by this resource.
func (r *ResourceInfo) SubResources() []table.Resource {
func (r *resourceInfo) SubResources() []table.Resource {
var resources []table.Resource
for _, res := range r.resourceStatus.GeneratedResources {
resources = append(resources, &SubResourceInfo{
resources = append(resources, &subResourceInfo{
resourceStatus: res,
})
}
return resources
}

// SubResourceInfo captures the latest seen state of a
// subResourceInfo captures the latest seen state of a
// single subResource, i.e. resources that are created and
// managed by one of the top-level resources we either apply
// or prune.
type SubResourceInfo struct {
type subResourceInfo struct {
// resourceStatus contains the latest status information
// about the subResource.
resourceStatus *pe.ResourceStatus
}

// Identifier returns the identifier for the given subResource.
func (r *SubResourceInfo) Identifier() object.ObjMetadata {
func (r *subResourceInfo) Identifier() object.ObjMetadata {
return r.resourceStatus.Identifier
}

// ResourceStatus returns the latest seen status for the
// subResource.
func (r *SubResourceInfo) ResourceStatus() *pe.ResourceStatus {
func (r *subResourceInfo) ResourceStatus() *pe.ResourceStatus {
return r.resourceStatus
}

// SubResources returns a slice of Resource which contains
// any resources created and managed by this resource.
func (r *SubResourceInfo) SubResources() []table.Resource {
func (r *subResourceInfo) SubResources() []table.Resource {
var resources []table.Resource
for _, res := range r.resourceStatus.GeneratedResources {
resources = append(resources, &SubResourceInfo{
resources = append(resources, &subResourceInfo{
resourceStatus: res,
})
}
Expand All @@ -162,7 +162,7 @@ func (r *SubResourceInfo) SubResources() []table.Resource {
// The function returns a channel. When this channel is closed, the
// goroutine has processed all events in the eventChannel and
// exited.
func (r *ResourceStateCollector) Listen(eventChannel <-chan event.Event) <-chan listenerResult {
func (r *resourceStateCollector) Listen(eventChannel <-chan event.Event) <-chan listenerResult {
completed := make(chan listenerResult)
go func() {
defer close(completed)
Expand All @@ -181,7 +181,7 @@ type listenerResult struct {
}

// processEvent processes an event and updates the state.
func (r *ResourceStateCollector) processEvent(ev event.Event) error {
func (r *resourceStateCollector) processEvent(ev event.Event) error {
r.mux.Lock()
defer r.mux.Unlock()
switch ev.Type {
Expand All @@ -203,7 +203,7 @@ func (r *ResourceStateCollector) processEvent(ev event.Event) error {

// processValidationEvent handles events pertaining to a validation error
// for a resource.
func (r *ResourceStateCollector) processValidationEvent(e event.ValidationEvent) error {
func (r *resourceStateCollector) processValidationEvent(e event.ValidationEvent) error {
klog.V(7).Infoln("processing validation event")
// unwrap validation errors
err := e.Error
Expand Down Expand Up @@ -231,7 +231,7 @@ func (r *ResourceStateCollector) processValidationEvent(e event.ValidationEvent)

// processStatusEvent handles events pertaining to a status
// update for a resource.
func (r *ResourceStateCollector) processStatusEvent(e event.StatusEvent) {
func (r *resourceStateCollector) processStatusEvent(e event.StatusEvent) {
klog.V(7).Infoln("processing status event")
previous, found := r.resourceInfos[e.Identifier]
if !found {
Expand All @@ -242,7 +242,7 @@ func (r *ResourceStateCollector) processStatusEvent(e event.StatusEvent) {
}

// processApplyEvent handles events relating to apply operations
func (r *ResourceStateCollector) processApplyEvent(e event.ApplyEvent) {
func (r *resourceStateCollector) processApplyEvent(e event.ApplyEvent) {
identifier := e.Identifier
klog.V(7).Infof("processing apply event for %s", identifier)
previous, found := r.resourceInfos[identifier]
Expand All @@ -257,7 +257,7 @@ func (r *ResourceStateCollector) processApplyEvent(e event.ApplyEvent) {
}

// processPruneEvent handles event related to prune operations.
func (r *ResourceStateCollector) processPruneEvent(e event.PruneEvent) {
func (r *resourceStateCollector) processPruneEvent(e event.PruneEvent) {
identifier := e.Identifier
klog.V(7).Infof("processing prune event for %s", identifier)
previous, found := r.resourceInfos[identifier]
Expand All @@ -272,7 +272,7 @@ func (r *ResourceStateCollector) processPruneEvent(e event.PruneEvent) {
}

// processPruneEvent handles event related to prune operations.
func (r *ResourceStateCollector) processWaitEvent(e event.WaitEvent) {
func (r *resourceStateCollector) processWaitEvent(e event.WaitEvent) {
identifier := e.Identifier
klog.V(7).Infof("processing wait event for %s", identifier)
previous, found := r.resourceInfos[identifier]
Expand Down Expand Up @@ -306,13 +306,13 @@ func (r *ResourceState) Error() error {

// LatestState returns a ResourceState object that contains
// a copy of the latest state for all resources.
func (r *ResourceStateCollector) LatestState() *ResourceState {
func (r *resourceStateCollector) LatestState() *ResourceState {
r.mux.RLock()
defer r.mux.RUnlock()

var resourceInfos ResourceInfos
for _, ri := range r.resourceInfos {
resourceInfos = append(resourceInfos, &ResourceInfo{
resourceInfos = append(resourceInfos, &resourceInfo{
identifier: ri.identifier,
resourceStatus: ri.resourceStatus,
ResourceAction: ri.ResourceAction,
Expand All @@ -332,7 +332,7 @@ func (r *ResourceStateCollector) LatestState() *ResourceState {

// Stats returns a summary of the results from the actuation operation
// as a stats.Stats object.
func (r *ResourceStateCollector) Stats() stats.Stats {
func (r *resourceStateCollector) Stats() stats.Stats {
var s stats.Stats
for _, res := range r.resourceInfos {
switch res.ResourceAction {
Expand All @@ -357,7 +357,7 @@ func (r *ResourceStateCollector) Stats() stats.Stats {
return s
}

type ResourceInfos []*ResourceInfo
type ResourceInfos []*resourceInfo

func (g ResourceInfos) Len() int {
return len(g)
Expand Down
8 changes: 4 additions & 4 deletions pkg/printers/table/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const testMessage = "test message for ResourceStatus"
func TestResourceStateCollector_New(t *testing.T) {
testCases := map[string]struct {
resourceGroups []event.ActionGroup
resourceInfos map[object.ObjMetadata]*ResourceInfo
resourceInfos map[object.ObjMetadata]*resourceInfo
}{
"no resources": {
resourceGroups: []event.ActionGroup{},
resourceInfos: map[object.ObjMetadata]*ResourceInfo{},
resourceInfos: map[object.ObjMetadata]*resourceInfo{},
},
"several resources for apply": {
resourceGroups: []event.ActionGroup{
Expand All @@ -63,7 +63,7 @@ func TestResourceStateCollector_New(t *testing.T) {
},
},
},
resourceInfos: map[object.ObjMetadata]*ResourceInfo{
resourceInfos: map[object.ObjMetadata]*resourceInfo{
depID: {
ResourceAction: event.ApplyAction,
},
Expand All @@ -87,7 +87,7 @@ func TestResourceStateCollector_New(t *testing.T) {
},
},
},
resourceInfos: map[object.ObjMetadata]*ResourceInfo{
resourceInfos: map[object.ObjMetadata]*resourceInfo{
depID: {
ResourceAction: event.PruneAction,
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/printers/table/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ var (
ColumnWidth: 12,
PrintResourceFunc: func(w io.Writer, width int, r table.Resource) (int,
error) {
var resInfo *ResourceInfo
var resInfo *resourceInfo
switch res := r.(type) {
case *ResourceInfo:
case *resourceInfo:
resInfo = res
default:
return 0, nil
Expand Down Expand Up @@ -122,9 +122,9 @@ var (
int,
error,
) {
var resInfo *ResourceInfo
var resInfo *resourceInfo
switch res := r.(type) {
case *ResourceInfo:
case *resourceInfo:
resInfo = res
default:
return 0, nil
Expand Down Expand Up @@ -158,7 +158,7 @@ var (

// runPrintLoop starts a new goroutine that will regularly fetch the
// latest state from the collector and update the table.
func (t *Printer) runPrintLoop(coll *ResourceStateCollector, stop chan struct{}) chan struct{} {
func (t *Printer) runPrintLoop(coll *resourceStateCollector, stop chan struct{}) chan struct{} {
finished := make(chan struct{})

baseTablePrinter := table.BaseTablePrinter{
Expand Down
10 changes: 5 additions & 5 deletions pkg/printers/table/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ func TestActionColumnDef(t *testing.T) {
expectedOutput string
}{
"unexpected implementation of Resource interface": {
resource: &SubResourceInfo{},
resource: &subResourceInfo{},
columnWidth: 15,
expectedOutput: "",
},
"neither applied nor pruned": {
resource: &ResourceInfo{},
resource: &resourceInfo{},
columnWidth: 15,
expectedOutput: "",
},
"applied": {
resource: &ResourceInfo{
resource: &resourceInfo{
ResourceAction: event.ApplyAction,
ApplyOpResult: createdOpResult,
},
columnWidth: 15,
expectedOutput: "Created",
},
"pruned": {
resource: &ResourceInfo{
resource: &resourceInfo{
ResourceAction: event.PruneAction,
PruneOpResult: prunedOpResult,
},
columnWidth: 15,
expectedOutput: "Pruned",
},
"trimmed output": {
resource: &ResourceInfo{
resource: &resourceInfo{
ResourceAction: event.ApplyAction,
ApplyOpResult: createdOpResult,
},
Expand Down

0 comments on commit 5d23501

Please sign in to comment.