feat: only show remote configs used in deployment
This commit is contained in:
@ -211,16 +211,10 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
secretInfo = append(secretInfo, fmt.Sprintf("%s: %s", secStat.LocalName, secStat.Version))
|
||||
}
|
||||
|
||||
configFilters, err := app.Filters(false, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
}
|
||||
configList, err := client.GetConfigs(cl, context.Background(), app.Server, configFilters)
|
||||
configNames, err := client.GetConfigNamesForStack(cl, context.Background(), app.StackName())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
configNames := client.GetConfigNames(configList)
|
||||
|
||||
var configInfo []string
|
||||
for _, config := range configNames {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
@ -46,3 +47,38 @@ func GetConfigNameAndVersion(fullName string, stackName string) (string, string)
|
||||
}
|
||||
return name, ""
|
||||
}
|
||||
|
||||
// GetConfigNamesForStack retrieves all Docker configs attached to services in a given stack.
|
||||
func GetConfigNamesForStack(cl *client.Client, ctx context.Context, stackName string) ([]string, error) {
|
||||
// Create filter to get services for the specific stack
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", "com.docker.stack.namespace="+stackName)
|
||||
|
||||
// List all services in the stack
|
||||
services, err := cl.ServiceList(ctx, types.ServiceListOptions{
|
||||
Filters: filter,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Collect unique config names from all services
|
||||
configNames := make(map[string]bool)
|
||||
for _, service := range services {
|
||||
if service.Spec.TaskTemplate.ContainerSpec != nil {
|
||||
for _, configRef := range service.Spec.TaskTemplate.ContainerSpec.Configs {
|
||||
if configRef.ConfigName != "" {
|
||||
configNames[configRef.ConfigName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert map to slice
|
||||
result := make([]string, 0, len(configNames))
|
||||
for name := range configNames {
|
||||
result = append(result, name)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user