mirror of
https://github.com/crazy-max/diun.git
synced 2025-04-14 07:08:32 +00:00
Coding style
This commit is contained in:
parent
74869c2ab4
commit
51c0e3caca
9 changed files with 11 additions and 10 deletions
internal
pkg/docker
|
@ -182,7 +182,6 @@ func (di *Diun) getRegOpts(id string) (model.RegOpts, error) {
|
||||||
}
|
}
|
||||||
if regopts, ok := di.cfg.RegOpts[id]; ok {
|
if regopts, ok := di.cfg.RegOpts[id]; ok {
|
||||||
return regopts, nil
|
return regopts, nil
|
||||||
} else {
|
|
||||||
return model.RegOpts{}, fmt.Errorf("%s not found", id)
|
|
||||||
}
|
}
|
||||||
|
return model.RegOpts{}, fmt.Errorf("%s not found", id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ type Image struct {
|
||||||
ExcludeTags []string `yaml:"exclude_tags,omitempty" json:",omitempty"`
|
ExcludeTags []string `yaml:"exclude_tags,omitempty" json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Image status constants
|
||||||
const (
|
const (
|
||||||
ImageStatusNew = ImageStatus("new")
|
ImageStatusNew = ImageStatus("new")
|
||||||
ImageStatusUpdate = ImageStatus("update")
|
ImageStatusUpdate = ImageStatus("update")
|
||||||
|
|
|
@ -10,7 +10,7 @@ type Providers struct {
|
||||||
// PrdDocker holds docker provider configuration
|
// PrdDocker holds docker provider configuration
|
||||||
type PrdDocker struct {
|
type PrdDocker struct {
|
||||||
Endpoint string `yaml:"endpoint,omitempty" json:",omitempty"`
|
Endpoint string `yaml:"endpoint,omitempty" json:",omitempty"`
|
||||||
ApiVersion string `yaml:"api_version,omitempty" json:",omitempty"`
|
APIVersion string `yaml:"api_version,omitempty" json:",omitempty"`
|
||||||
TLSCertsPath string `yaml:"tls_certs_path,omitempty" json:",omitempty"`
|
TLSCertsPath string `yaml:"tls_certs_path,omitempty" json:",omitempty"`
|
||||||
TLSVerify bool `yaml:"tls_verify,omitempty" json:",omitempty"`
|
TLSVerify bool `yaml:"tls_verify,omitempty" json:",omitempty"`
|
||||||
WatchByDefault bool `yaml:"watch_by_default,omitempty" json:",omitempty"`
|
WatchByDefault bool `yaml:"watch_by_default,omitempty" json:",omitempty"`
|
||||||
|
@ -20,7 +20,7 @@ type PrdDocker struct {
|
||||||
// PrdSwarm holds swarm provider configuration
|
// PrdSwarm holds swarm provider configuration
|
||||||
type PrdSwarm struct {
|
type PrdSwarm struct {
|
||||||
Endpoint string `yaml:"endpoint,omitempty" json:",omitempty"`
|
Endpoint string `yaml:"endpoint,omitempty" json:",omitempty"`
|
||||||
ApiVersion string `yaml:"api_version,omitempty" json:",omitempty"`
|
APIVersion string `yaml:"api_version,omitempty" json:",omitempty"`
|
||||||
TLSCertsPath string `yaml:"tls_certs_path,omitempty" json:",omitempty"`
|
TLSCertsPath string `yaml:"tls_certs_path,omitempty" json:",omitempty"`
|
||||||
TLSVerify bool `yaml:"tls_verify,omitempty" json:",omitempty"`
|
TLSVerify bool `yaml:"tls_verify,omitempty" json:",omitempty"`
|
||||||
WatchByDefault bool `yaml:"watch_by_default,omitempty" json:",omitempty"`
|
WatchByDefault bool `yaml:"watch_by_default,omitempty" json:",omitempty"`
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/crazy-max/diun/internal/model"
|
"github.com/crazy-max/diun/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ValidateContainerImage returns a standard image through Docker labels
|
||||||
func ValidateContainerImage(image string, labels map[string]string, watchByDef bool) (img model.Image, err error) {
|
func ValidateContainerImage(image string, labels map[string]string, watchByDef bool) (img model.Image, err error) {
|
||||||
if i := strings.Index(image, "@sha256:"); i > 0 {
|
if i := strings.Index(image, "@sha256:"); i > 0 {
|
||||||
image = image[:i]
|
image = image[:i]
|
||||||
|
|
|
@ -16,7 +16,7 @@ func (c *Client) listContainerImage(id string, elt model.PrdDocker) []model.Imag
|
||||||
Str("provider", fmt.Sprintf("docker-%s", id)).
|
Str("provider", fmt.Sprintf("docker-%s", id)).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
cli, err := docker.NewClient(elt.Endpoint, elt.ApiVersion, elt.TLSCertsPath, elt.TLSVerify)
|
cli, err := docker.NewClient(elt.Endpoint, elt.APIVersion, elt.TLSCertsPath, elt.TLSVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sublog.Error().Err(err).Msg("Cannot create Docker client")
|
sublog.Error().Err(err).Msg("Cannot create Docker client")
|
||||||
return []model.Image{}
|
return []model.Image{}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func (c *Client) listServiceImage(id string, elt model.PrdSwarm) []model.Image {
|
||||||
Str("provider", fmt.Sprintf("swarm-%s", id)).
|
Str("provider", fmt.Sprintf("swarm-%s", id)).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
cli, err := docker.NewClient(elt.Endpoint, elt.ApiVersion, elt.TLSCertsPath, elt.TLSVerify)
|
cli, err := docker.NewClient(elt.Endpoint, elt.APIVersion, elt.TLSCertsPath, elt.TLSVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sublog.Error().Err(err).Msg("Cannot create Docker client")
|
sublog.Error().Err(err).Msg("Cannot create Docker client")
|
||||||
return []model.Image{}
|
return []model.Image{}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
// Client represents an active docker object
|
// Client represents an active docker object
|
||||||
type Client struct {
|
type Client struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
Api *client.Client
|
API *client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient initializes a new Docker API client with default values
|
// NewClient initializes a new Docker API client with default values
|
||||||
|
@ -56,6 +56,6 @@ func NewClient(endpoint, apiVersion, tlsCertsPath string, tlsVerify bool) (*Clie
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
Api: cli,
|
API: cli,
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
// ContainerList returns Docker containers
|
// ContainerList returns Docker containers
|
||||||
func (c *Client) ContainerList(filterArgs filters.Args) ([]types.Container, error) {
|
func (c *Client) ContainerList(filterArgs filters.Args) ([]types.Container, error) {
|
||||||
containers, err := c.Api.ContainerList(c.ctx, types.ContainerListOptions{
|
containers, err := c.API.ContainerList(c.ctx, types.ContainerListOptions{
|
||||||
Filters: filterArgs,
|
Filters: filterArgs,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// ServiceList returns Swarm services
|
// ServiceList returns Swarm services
|
||||||
func (c *Client) ServiceList(filterArgs filters.Args) ([]swarm.Service, error) {
|
func (c *Client) ServiceList(filterArgs filters.Args) ([]swarm.Service, error) {
|
||||||
services, err := c.Api.ServiceList(c.ctx, types.ServiceListOptions{
|
services, err := c.API.ServiceList(c.ctx, types.ServiceListOptions{
|
||||||
Filters: filterArgs,
|
Filters: filterArgs,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue