mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
chore: modernize the codebase using go 1.26 (#278)
This runs: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./... ``` over the codebase, as this is using go 1.26, it can also use the new new() functionallity so AsPtr and boolPtr is are needed anymore. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
+36
-36
@@ -39,25 +39,25 @@ func (m *mockClusterClient) ListMachines(ctx context.Context, in *emptypb.Empty,
|
|||||||
|
|
||||||
func TestCollectContainers_NilMetadata(t *testing.T) {
|
func TestCollectContainers_NilMetadata(t *testing.T) {
|
||||||
// Setup container data
|
// Setup container data
|
||||||
containerData := map[string]interface{}{
|
containerData := map[string]any{
|
||||||
"Id": "container1",
|
"Id": "container1",
|
||||||
"Name": "test-container",
|
"Name": "test-container",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "test-image",
|
"Image": "test-image",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON, err := json.Marshal(containerData)
|
containerJSON, err := json.Marshal(containerData)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
serviceSpecJSON, err := json.Marshal(map[string]interface{}{})
|
serviceSpecJSON, err := json.Marshal(map[string]any{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Setup mocks
|
// Setup mocks
|
||||||
@@ -120,28 +120,28 @@ func TestCollectContainers_NilMetadata_MultipleMachines_Error(t *testing.T) {
|
|||||||
// If we have multiple machines but receive nil metadata, it should return an error as it is ambiguous
|
// If we have multiple machines but receive nil metadata, it should return an error as it is ambiguous
|
||||||
|
|
||||||
// Setup container data
|
// Setup container data
|
||||||
containerData1 := map[string]interface{}{
|
containerData1 := map[string]any{
|
||||||
"Id": "container1",
|
"Id": "container1",
|
||||||
}
|
}
|
||||||
containerJSON1, _ := json.Marshal(containerData1)
|
containerJSON1, _ := json.Marshal(containerData1)
|
||||||
|
|
||||||
containerData2 := map[string]interface{}{
|
containerData2 := map[string]any{
|
||||||
"Id": "container2",
|
"Id": "container2",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "test-image",
|
"Image": "test-image",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON2, _ := json.Marshal(containerData2)
|
containerJSON2, _ := json.Marshal(containerData2)
|
||||||
|
|
||||||
serviceSpecJSON, _ := json.Marshal(map[string]interface{}{})
|
serviceSpecJSON, _ := json.Marshal(map[string]any{})
|
||||||
|
|
||||||
// Setup mocks
|
// Setup mocks
|
||||||
mockDocker := &mockDockerClient{
|
mockDocker := &mockDockerClient{
|
||||||
@@ -210,41 +210,41 @@ func TestCollectContainers_MetadataPresent_MultipleMachines(t *testing.T) {
|
|||||||
// Verify correct mapping of containers to machines when metadata is present
|
// Verify correct mapping of containers to machines when metadata is present
|
||||||
|
|
||||||
// Setup container data
|
// Setup container data
|
||||||
containerData1 := map[string]interface{}{
|
containerData1 := map[string]any{
|
||||||
"Id": "container1",
|
"Id": "container1",
|
||||||
"Name": "container-1",
|
"Name": "container-1",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "image-1",
|
"Image": "image-1",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON1, _ := json.Marshal(containerData1)
|
containerJSON1, _ := json.Marshal(containerData1)
|
||||||
|
|
||||||
containerData2 := map[string]interface{}{
|
containerData2 := map[string]any{
|
||||||
"Id": "container2",
|
"Id": "container2",
|
||||||
"Name": "container-2",
|
"Name": "container-2",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "image-2",
|
"Image": "image-2",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON2, _ := json.Marshal(containerData2)
|
containerJSON2, _ := json.Marshal(containerData2)
|
||||||
|
|
||||||
serviceSpecJSON, _ := json.Marshal(map[string]interface{}{})
|
serviceSpecJSON, _ := json.Marshal(map[string]any{})
|
||||||
|
|
||||||
// Setup mocks
|
// Setup mocks
|
||||||
mockDocker := &mockDockerClient{
|
mockDocker := &mockDockerClient{
|
||||||
@@ -321,22 +321,22 @@ func TestCollectContainers_MetadataPresent_MultipleMachines(t *testing.T) {
|
|||||||
func TestCollectContainers_NilMetadata_NoMachines(t *testing.T) {
|
func TestCollectContainers_NilMetadata_NoMachines(t *testing.T) {
|
||||||
// Case: 1 msc with nil metadata but no machines at all
|
// Case: 1 msc with nil metadata but no machines at all
|
||||||
|
|
||||||
containerData := map[string]interface{}{
|
containerData := map[string]any{
|
||||||
"Id": "container1",
|
"Id": "container1",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "test-image",
|
"Image": "test-image",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON, _ := json.Marshal(containerData)
|
containerJSON, _ := json.Marshal(containerData)
|
||||||
serviceSpecJSON, _ := json.Marshal(map[string]interface{}{})
|
serviceSpecJSON, _ := json.Marshal(map[string]any{})
|
||||||
|
|
||||||
mockDocker := &mockDockerClient{
|
mockDocker := &mockDockerClient{
|
||||||
listResp: &pb.ListServiceContainersResponse{
|
listResp: &pb.ListServiceContainersResponse{
|
||||||
@@ -378,22 +378,22 @@ func TestCollectContainers_NilMetadata_NoMachines(t *testing.T) {
|
|||||||
func TestCollectContainers_MetadataPresent_NotInMapping(t *testing.T) {
|
func TestCollectContainers_MetadataPresent_NotInMapping(t *testing.T) {
|
||||||
// Case: msc with metadata that is not in the IP-to-name mapping
|
// Case: msc with metadata that is not in the IP-to-name mapping
|
||||||
|
|
||||||
containerData := map[string]interface{}{
|
containerData := map[string]any{
|
||||||
"Id": "container1",
|
"Id": "container1",
|
||||||
"Config": map[string]interface{}{
|
"Config": map[string]any{
|
||||||
"Image": "test-image",
|
"Image": "test-image",
|
||||||
},
|
},
|
||||||
"State": map[string]interface{}{
|
"State": map[string]any{
|
||||||
"Status": "running",
|
"Status": "running",
|
||||||
"StartedAt": "2023-01-01T12:00:00Z",
|
"StartedAt": "2023-01-01T12:00:00Z",
|
||||||
"FinishedAt": "0001-01-01T00:00:00Z",
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
},
|
},
|
||||||
"NetworkSettings": map[string]interface{}{
|
"NetworkSettings": map[string]any{
|
||||||
"Networks": map[string]interface{}{},
|
"Networks": map[string]any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerJSON, _ := json.Marshal(containerData)
|
containerJSON, _ := json.Marshal(containerData)
|
||||||
serviceSpecJSON, _ := json.Marshal(map[string]interface{}{})
|
serviceSpecJSON, _ := json.Marshal(map[string]any{})
|
||||||
|
|
||||||
mockDocker := &mockDockerClient{
|
mockDocker := &mockDockerClient{
|
||||||
listResp: &pb.ListServiceContainersResponse{
|
listResp: &pb.ListServiceContainersResponse{
|
||||||
|
|||||||
@@ -358,8 +358,8 @@ func parseVolumeFlagValue(volume string) (api.VolumeSpec, api.VolumeMount, error
|
|||||||
volumeNoCopy := false
|
volumeNoCopy := false
|
||||||
|
|
||||||
if len(parts) == 3 {
|
if len(parts) == 3 {
|
||||||
opts := strings.Split(parts[2], ",")
|
opts := strings.SplitSeq(parts[2], ",")
|
||||||
for _, opt := range opts {
|
for opt := range opts {
|
||||||
switch opt {
|
switch opt {
|
||||||
case "ro", "readonly":
|
case "ro", "readonly":
|
||||||
mount.ReadOnly = true
|
mount.ReadOnly = true
|
||||||
|
|||||||
+12
-12
@@ -17,57 +17,57 @@ func newIPFSLogger(l *slog.Logger) *ipfsLogger {
|
|||||||
return &ipfsLogger{log: *l}
|
return &ipfsLogger{log: *l}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Debug(args ...interface{}) {
|
func (l *ipfsLogger) Debug(args ...any) {
|
||||||
l.log.Debug(fmt.Sprint(args...))
|
l.log.Debug(fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Debugf(format string, args ...interface{}) {
|
func (l *ipfsLogger) Debugf(format string, args ...any) {
|
||||||
l.log.Debug(fmt.Sprintf(format, args...))
|
l.log.Debug(fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Error(args ...interface{}) {
|
func (l *ipfsLogger) Error(args ...any) {
|
||||||
l.log.Error(fmt.Sprint(args...))
|
l.log.Error(fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Errorf(format string, args ...interface{}) {
|
func (l *ipfsLogger) Errorf(format string, args ...any) {
|
||||||
l.log.Error(fmt.Sprintf(format, args...))
|
l.log.Error(fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Fatal(args ...interface{}) {
|
func (l *ipfsLogger) Fatal(args ...any) {
|
||||||
l.log.Error(fmt.Sprint(args...))
|
l.log.Error(fmt.Sprint(args...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Fatalf(format string, args ...interface{}) {
|
func (l *ipfsLogger) Fatalf(format string, args ...any) {
|
||||||
l.log.Error(fmt.Sprintf(format, args...))
|
l.log.Error(fmt.Sprintf(format, args...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Info(args ...interface{}) {
|
func (l *ipfsLogger) Info(args ...any) {
|
||||||
l.log.Info(fmt.Sprint(args...))
|
l.log.Info(fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Infof(format string, args ...interface{}) {
|
func (l *ipfsLogger) Infof(format string, args ...any) {
|
||||||
l.log.Info(fmt.Sprintf(format, args...))
|
l.log.Info(fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Panic(args ...interface{}) {
|
func (l *ipfsLogger) Panic(args ...any) {
|
||||||
msg := fmt.Sprint(args...)
|
msg := fmt.Sprint(args...)
|
||||||
l.log.Error(msg)
|
l.log.Error(msg)
|
||||||
panic(msg)
|
panic(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Panicf(format string, args ...interface{}) {
|
func (l *ipfsLogger) Panicf(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
l.log.Error(msg)
|
l.log.Error(msg)
|
||||||
panic(msg)
|
panic(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Warn(args ...interface{}) {
|
func (l *ipfsLogger) Warn(args ...any) {
|
||||||
l.log.Warn(fmt.Sprint(args...))
|
l.log.Warn(fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ipfsLogger) Warnf(format string, args ...interface{}) {
|
func (l *ipfsLogger) Warnf(format string, args ...any) {
|
||||||
l.log.Warn(fmt.Sprintf(format, args...))
|
l.log.Warn(fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func ExpandCommaSeparatedValues(values []string) []string {
|
|||||||
|
|
||||||
var expanded []string
|
var expanded []string
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
for _, v := range strings.Split(value, ",") {
|
for v := range strings.SplitSeq(value, ",") {
|
||||||
if v = strings.TrimSpace(v); v != "" {
|
if v = strings.TrimSpace(v); v != "" {
|
||||||
expanded = append(expanded, v)
|
expanded = append(expanded, v)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ type RecordResponse struct {
|
|||||||
type AuthErrorResponse struct {
|
type AuthErrorResponse struct {
|
||||||
Status int `json:"status,omitempty"`
|
Status int `json:"status,omitempty"`
|
||||||
Message string `json:"msg,omitempty"`
|
Message string `json:"msg,omitempty"`
|
||||||
Data authErrorData `json:"data,omitempty"`
|
Data authErrorData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type authErrorData struct {
|
type authErrorData struct {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func (d *Director) remoteBackend(addr string) (*RemoteBackend, error) {
|
|||||||
|
|
||||||
// FlushRemoteBackends closes all remote backend connections and removes them from the cache.
|
// FlushRemoteBackends closes all remote backend connections and removes them from the cache.
|
||||||
func (d *Director) FlushRemoteBackends() {
|
func (d *Director) FlushRemoteBackends() {
|
||||||
d.remoteBackends.Range(func(key, value interface{}) bool {
|
d.remoteBackends.Range(func(key, value any) bool {
|
||||||
backend, ok := value.(*RemoteBackend)
|
backend, ok := value.(*RemoteBackend)
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -226,12 +226,13 @@ func (g *CaddyfileGenerator) Generate(
|
|||||||
|
|
||||||
// Append error summary as comment if there were any invalid configs.
|
// Append error summary as comment if there were any invalid configs.
|
||||||
if len(configErrors) > 0 {
|
if len(configErrors) > 0 {
|
||||||
errorsComment := "# Skipped invalid user-defined configs:\n"
|
var errorsComment strings.Builder
|
||||||
|
errorsComment.WriteString("# Skipped invalid user-defined configs:\n")
|
||||||
for _, e := range configErrors {
|
for _, e := range configErrors {
|
||||||
errorsComment += fmt.Sprintf("# - %s\n", e)
|
errorsComment.WriteString(fmt.Sprintf("# - %s\n", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
caddyfile += "\n" + errorsComment
|
caddyfile += "\n" + errorsComment.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return caddyfileHeader + "\n" + caddyfile, nil
|
return caddyfileHeader + "\n" + caddyfile, nil
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func createIptablesChains() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
firstRejectRuleNum := 0
|
firstRejectRuleNum := 0
|
||||||
for _, line := range strings.Split(string(out), "\n") {
|
for line := range strings.SplitSeq(string(out), "\n") {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) < 2 {
|
if len(fields) < 2 {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func (p *Proxy) handleConnection(ctx context.Context, localConn net.Conn) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Wait for both copies to complete or context cancel.
|
// Wait for both copies to complete or context cancel.
|
||||||
for i := 0; i < 2; i++ {
|
for range 2 {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// Close connections to abort ongoing copies.
|
// Close connections to abort ongoing copies.
|
||||||
|
|||||||
+3
-1
@@ -62,6 +62,8 @@ type VolumeClient interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AsPtr returns a pointer to the given value. Useful for optional fields in API structs.
|
// AsPtr returns a pointer to the given value. Useful for optional fields in API structs.
|
||||||
|
//
|
||||||
|
//go:fix inline
|
||||||
func AsPtr[T any](v T) *T {
|
func AsPtr[T any](v T) *T {
|
||||||
return &v
|
return new(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// uint64Ptr is a convenience function to create a pointer to a uint64 value
|
|
||||||
func uint64Ptr(v uint64) *uint64 {
|
|
||||||
return &v
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfigMount_GetNumericUid(t *testing.T) {
|
func TestConfigMount_GetNumericUid(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -30,12 +25,12 @@ func TestConfigMount_GetNumericUid(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "valid numeric uid",
|
name: "valid numeric uid",
|
||||||
uid: "1000",
|
uid: "1000",
|
||||||
expected: uint64Ptr(1000),
|
expected: new(uint64(1000)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero uid",
|
name: "zero uid",
|
||||||
uid: "0",
|
uid: "0",
|
||||||
expected: uint64Ptr(0),
|
expected: new(uint64(0)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid non-numeric uid",
|
name: "invalid non-numeric uid",
|
||||||
@@ -96,12 +91,12 @@ func TestConfigMount_GetNumericGid(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "valid numeric gid",
|
name: "valid numeric gid",
|
||||||
gid: "1000",
|
gid: "1000",
|
||||||
expected: uint64Ptr(1000),
|
expected: new(uint64(1000)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero gid",
|
name: "zero gid",
|
||||||
gid: "0",
|
gid: "0",
|
||||||
expected: uint64Ptr(0),
|
expected: new(uint64(0)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid non-numeric gid",
|
name: "invalid non-numeric gid",
|
||||||
|
|||||||
+3
-7
@@ -73,7 +73,7 @@ type ServiceSpec struct {
|
|||||||
// Default is 10 seconds if not specified.
|
// Default is 10 seconds if not specified.
|
||||||
StopGracePeriod *time.Duration `json:",omitempty"`
|
StopGracePeriod *time.Duration `json:",omitempty"`
|
||||||
// UpdateConfig configures how the service is updated during a deployment.
|
// UpdateConfig configures how the service is updated during a deployment.
|
||||||
UpdateConfig UpdateConfig `json:",omitempty"`
|
UpdateConfig UpdateConfig
|
||||||
// Volumes is list of data volumes that can be mounted into the container.
|
// Volumes is list of data volumes that can be mounted into the container.
|
||||||
Volumes []VolumeSpec
|
Volumes []VolumeSpec
|
||||||
}
|
}
|
||||||
@@ -348,9 +348,7 @@ func (s *ContainerSpec) Clone() ContainerSpec {
|
|||||||
}
|
}
|
||||||
if s.Env != nil {
|
if s.Env != nil {
|
||||||
spec.Env = make(EnvVars, len(s.Env))
|
spec.Env = make(EnvVars, len(s.Env))
|
||||||
for k, v := range s.Env {
|
maps.Copy(spec.Env, s.Env)
|
||||||
spec.Env[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if s.Healthcheck != nil {
|
if s.Healthcheck != nil {
|
||||||
hc := *s.Healthcheck
|
hc := *s.Healthcheck
|
||||||
@@ -380,9 +378,7 @@ func (s *ContainerSpec) Clone() ContainerSpec {
|
|||||||
}
|
}
|
||||||
if s.Sysctls != nil {
|
if s.Sysctls != nil {
|
||||||
spec.Sysctls = make(map[string]string, len(s.Sysctls))
|
spec.Sysctls = make(map[string]string, len(s.Sysctls))
|
||||||
for k, v := range s.Sysctls {
|
maps.Copy(spec.Sysctls, s.Sysctls)
|
||||||
spec.Sysctls[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if s.Resources.Ulimits != nil {
|
if s.Resources.Ulimits != nil {
|
||||||
spec.Resources.Ulimits = maps.Clone(s.Resources.Ulimits)
|
spec.Resources.Ulimits = maps.Clone(s.Resources.Ulimits)
|
||||||
|
|||||||
@@ -9,12 +9,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// boolPtr is a convenience function to create a pointer to a uint64 value
|
|
||||||
// TODO: Make this a generic function that works for any type
|
|
||||||
func boolPtr(b bool) *bool {
|
|
||||||
return &b
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServiceSpec_Validate_CaddyAndPorts(t *testing.T) {
|
func TestServiceSpec_Validate_CaddyAndPorts(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -219,7 +213,7 @@ func TestContainerSpec_Clone(t *testing.T) {
|
|||||||
"BAZ": "qux",
|
"BAZ": "qux",
|
||||||
},
|
},
|
||||||
Image: "nginx:latest",
|
Image: "nginx:latest",
|
||||||
Init: boolPtr(true),
|
Init: new(true),
|
||||||
LogDriver: &LogDriver{
|
LogDriver: &LogDriver{
|
||||||
Name: "json-file",
|
Name: "json-file",
|
||||||
Options: map[string]string{
|
Options: map[string]string{
|
||||||
|
|||||||
+3
-6
@@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"reflect"
|
"reflect"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -165,18 +166,14 @@ func (v *VolumeSpec) Clone() VolumeSpec {
|
|||||||
driver := *v.VolumeOptions.Driver
|
driver := *v.VolumeOptions.Driver
|
||||||
if driver.Options != nil {
|
if driver.Options != nil {
|
||||||
driver.Options = make(map[string]string, len(v.VolumeOptions.Driver.Options))
|
driver.Options = make(map[string]string, len(v.VolumeOptions.Driver.Options))
|
||||||
for k, val := range v.VolumeOptions.Driver.Options {
|
maps.Copy(driver.Options, v.VolumeOptions.Driver.Options)
|
||||||
driver.Options[k] = val
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
opts.Driver = &driver
|
opts.Driver = &driver
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Labels != nil {
|
if opts.Labels != nil {
|
||||||
opts.Labels = make(map[string]string, len(v.VolumeOptions.Labels))
|
opts.Labels = make(map[string]string, len(v.VolumeOptions.Labels))
|
||||||
for k, val := range v.VolumeOptions.Labels {
|
maps.Copy(opts.Labels, v.VolumeOptions.Labels)
|
||||||
opts.Labels[k] = val
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spec.VolumeOptions = &opts
|
spec.VolumeOptions = &opts
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const MachinesExtensionKey = "x-machines"
|
|||||||
type MachinesSource []string
|
type MachinesSource []string
|
||||||
|
|
||||||
// DecodeMapstructure implements custom decoding for multiple input types
|
// DecodeMapstructure implements custom decoding for multiple input types
|
||||||
func (m *MachinesSource) DecodeMapstructure(value interface{}) error {
|
func (m *MachinesSource) DecodeMapstructure(value any) error {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case *MachinesSource:
|
case *MachinesSource:
|
||||||
// Handle case where compose-go passes a pointer to an already created instance
|
// Handle case where compose-go passes a pointer to an already created instance
|
||||||
@@ -38,7 +38,7 @@ func (m *MachinesSource) DecodeMapstructure(value interface{}) error {
|
|||||||
}
|
}
|
||||||
*m = MachinesSource(machines)
|
*m = MachinesSource(machines)
|
||||||
return nil
|
return nil
|
||||||
case []interface{}:
|
case []any:
|
||||||
// Support interface array that may come from YAML parsing
|
// Support interface array that may come from YAML parsing
|
||||||
machineNames := make([]string, 0, len(v))
|
machineNames := make([]string, 0, len(v))
|
||||||
for i, machine := range v {
|
for i, machine := range v {
|
||||||
|
|||||||
@@ -346,9 +346,7 @@ func dockerVolumeSpecFromCompose(serviceVolume types.ServiceVolumeConfig, volume
|
|||||||
func mergeLabels(labels ...types.Labels) types.Labels {
|
func mergeLabels(labels ...types.Labels) types.Labels {
|
||||||
merged := types.Labels{}
|
merged := types.Labels{}
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
for k, v := range l {
|
maps.Copy(merged, l)
|
||||||
merged[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return merged
|
return merged
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -474,12 +474,10 @@ func toPushProgressEvent(jm jsonmessage.JSONMessage) *progress.Event {
|
|||||||
percent := 0
|
percent := 0
|
||||||
|
|
||||||
if jm.Progress.Total > 0 {
|
if jm.Progress.Total > 0 {
|
||||||
percent = int(jm.Progress.Current * 100 / jm.Progress.Total)
|
percent = min(
|
||||||
// Cap percent at 100 to prevent index out of bounds in progress display.
|
// Cap percent at 100 to prevent index out of bounds in progress display.
|
||||||
// Docker can report Current > Total in some cases (e.g., compression).
|
// Docker can report Current > Total in some cases (e.g., compression).
|
||||||
if percent > 100 {
|
int(jm.Progress.Current*100/jm.Progress.Total), 100)
|
||||||
percent = 100
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch jm.Status {
|
switch jm.Status {
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ func TestLogMerger_UnevenStreams(t *testing.T) {
|
|||||||
baseTime := time.Now()
|
baseTime := time.Now()
|
||||||
|
|
||||||
// Stream 1 sends many entries quickly (0ms - 104ms).
|
// Stream 1 sends many entries quickly (0ms - 104ms).
|
||||||
for i := 0; i < numFastEntries; i++ {
|
for i := range numFastEntries {
|
||||||
ch1 <- testEntry(api.LogStreamStdout, baseTime.Add(time.Duration(i)*time.Millisecond), "fast")
|
ch1 <- testEntry(api.LogStreamStdout, baseTime.Add(time.Duration(i)*time.Millisecond), "fast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1052,7 +1052,7 @@ myapp.example.com {
|
|||||||
// Machine 0: vol1, vol2
|
// Machine 0: vol1, vol2
|
||||||
// Machine 1: vol1, vol2
|
// Machine 1: vol1, vol2
|
||||||
// Machine 2: vol1
|
// Machine 2: vol1
|
||||||
for i := 0; i < 3; i++ {
|
for i := range 3 {
|
||||||
_, err := cli.CreateVolume(ctx, c.Machines[i].Name, volume.CreateOptions{Name: vol1Name})
|
_, err := cli.CreateVolume(ctx, c.Machines[i].Name, volume.CreateOptions{Name: vol1Name})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if i < 2 {
|
if i < 2 {
|
||||||
|
|||||||
Reference in New Issue
Block a user