Skip to content

Commit

Permalink
Rename files to match contents (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes authored Feb 1, 2024
1 parent e91435c commit 8c55110
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
64 changes: 64 additions & 0 deletions pkg/grizzly/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package grizzly

import (
"github.com/grafana/tanka/pkg/kubernetes/manifest"
)

// Handler describes a handler for a single API resource handled by a single provider
type Handler interface {
APIVersion() string
Kind() string

// FindResourceFiles identifies files within a directory that this handler can process
FindResourceFiles(dir string) ([]string, error)

// ResourceFilePath returns the location on disk where a resource should be updated
ResourceFilePath(resource Resource, filetype string) string

// Parse parses a manifest object into a struct for this resource type
Parse(m manifest.Manifest) (Resources, error)

// Unprepare removes unnecessary elements from a remote resource ready for presentation/comparison
Unprepare(resource Resource) *Resource

// Prepare gets a resource ready for dispatch to the remote endpoint
Prepare(existing, resource Resource) *Resource

// Retrieves a UID for a resource
GetUID(resource Resource) (string, error)

// Get retrieves JSON for a resource from an endpoint, by UID
GetByUID(UID string) (*Resource, error)

// GetRemote retrieves a remote equivalent of a remote resource
GetRemote(resource Resource) (*Resource, error)

// ListRemote retrieves as list of UIDs of all remote resources
ListRemote() ([]string, error)

// Add pushes a new resource to the endpoint
Add(resource Resource) error

// Update pushes an existing resource to the endpoint
Update(existing, resource Resource) error

// Validate gets or build the uid of corresponding resource
Validate(resource Resource) error

// Sort sorts resources as defined by the handler
Sort(resources Resources) Resources
}

// PreviewHandler describes a handler that has the ability to render
// a preview of a resource
type PreviewHandler interface {
// Preview renders Jsonnet then pushes them to the endpoint if previews are possible
Preview(resource Resource, opts *PreviewOpts) error
}

// ListenHandler describes a handler that has the ability to watch a single
// resource for changes, and write changes to that resource to a local file
type ListenHandler interface {
// Listen watches a resource and update local file on changes
Listen(UID, filename string) error
}
8 changes: 5 additions & 3 deletions pkg/grizzly/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ var Registry registry

// NewProviderRegistry returns a new registry instance
func ConfigureProviderRegistry(providers []Provider) {
Registry.Providers = providers
Registry.Handlers = map[string]Handler{}
Registry.HandlerOrder = []Handler{}
Registry.Providers = append(Registry.Providers, providers...)
if Registry.Handlers == nil {
Registry.Handlers = map[string]Handler{}
Registry.HandlerOrder = []Handler{}
}
for _, provider := range providers {
for _, handler := range provider.GetHandlers() {
Registry.Handlers[handler.Kind()] = handler
Expand Down
60 changes: 0 additions & 60 deletions pkg/grizzly/providers.go → pkg/grizzly/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"

"github.com/grafana/tanka/pkg/kubernetes/manifest"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -158,62 +157,3 @@ func (r *Resources) Sort() Resources {
}
return resources
}

// Handler describes a handler for a single API resource handled by a single provider
type Handler interface {
APIVersion() string
Kind() string

// FindResourceFiles identifies files within a directory that this handler can process
FindResourceFiles(dir string) ([]string, error)

// ResourceFilePath returns the location on disk where a resource should be updated
ResourceFilePath(resource Resource, filetype string) string

// Parse parses a manifest object into a struct for this resource type
Parse(m manifest.Manifest) (Resources, error)

// Unprepare removes unnecessary elements from a remote resource ready for presentation/comparison
Unprepare(resource Resource) *Resource

// Prepare gets a resource ready for dispatch to the remote endpoint
Prepare(existing, resource Resource) *Resource

// Retrieves a UID for a resource
GetUID(resource Resource) (string, error)

// Get retrieves JSON for a resource from an endpoint, by UID
GetByUID(UID string) (*Resource, error)

// GetRemote retrieves a remote equivalent of a remote resource
GetRemote(resource Resource) (*Resource, error)

// ListRemote retrieves as list of UIDs of all remote resources
ListRemote() ([]string, error)

// Add pushes a new resource to the endpoint
Add(resource Resource) error

// Update pushes an existing resource to the endpoint
Update(existing, resource Resource) error

// Validate gets or build the uid of corresponding resource
Validate(resource Resource) error

// Sort sorts resources as defined by the handler
Sort(resources Resources) Resources
}

// PreviewHandler describes a handler that has the ability to render
// a preview of a resource
type PreviewHandler interface {
// Preview renders Jsonnet then pushes them to the endpoint if previews are possible
Preview(resource Resource, opts *PreviewOpts) error
}

// ListenHandler describes a handler that has the ability to watch a single
// resource for changes, and write changes to that resource to a local file
type ListenHandler interface {
// Listen watches a resource and update local file on changes
Listen(UID, filename string) error
}

0 comments on commit 8c55110

Please sign in to comment.