chore: remove some duplication and add a first few tests
This commit is contained in:
+1
-34
@@ -19,12 +19,6 @@ type Client struct {
|
||||
|
||||
type Options func(*Client)
|
||||
|
||||
func WithInClusterProvider() func(c *Client) {
|
||||
return func(c *Client) {
|
||||
c.provider = &DefaultProvider{provider: &InClusterProvider{}}
|
||||
}
|
||||
}
|
||||
|
||||
func WithKubeConfigProvider(kubeconfig string) func(c *Client) {
|
||||
return func(c *Client) {
|
||||
c.provider = &DefaultProvider{provider: &PathConfigProvider{kubecfg: kubeconfig}}
|
||||
@@ -32,7 +26,7 @@ func WithKubeConfigProvider(kubeconfig string) func(c *Client) {
|
||||
}
|
||||
|
||||
func New(opts ...Options) *Client {
|
||||
c := &Client{}
|
||||
c := &Client{provider: &DefaultProvider{provider: &InClusterProvider{}}}
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
@@ -119,30 +113,3 @@ func (k PathConfigProvider) Provide() (*rest.Config, error) {
|
||||
}
|
||||
|
||||
var _ ConfigProvider = &PathConfigProvider{}
|
||||
|
||||
type ImageCollector map[string]map[string]struct{}
|
||||
|
||||
func NewImageCollector() ImageCollector {
|
||||
return make(map[string]map[string]struct{})
|
||||
}
|
||||
|
||||
func (c *ImageCollector) Add(image string) {
|
||||
parts := strings.Split(image[20:], ":")
|
||||
if x, exists := (*c)[parts[0]]; exists {
|
||||
x[parts[1]] = struct{}{}
|
||||
} else {
|
||||
(*c)[parts[0]] = map[string]struct{}{
|
||||
parts[1]: {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ImageCollector) Images() map[string][]string {
|
||||
images := make(map[string][]string)
|
||||
for i, x := range *c {
|
||||
for v := range x {
|
||||
images[i] = append(images[i], v)
|
||||
}
|
||||
}
|
||||
return images
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user