From de13aeea339bd72d8417b2aea5b51dd1dc540632 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 9 Jul 2023 12:32:19 +0200 Subject: [PATCH] Remove unused step options (#1957) remove them as they did never had any functionality --- pipeline/frontend/yaml/types/container.go | 35 +++-- .../frontend/yaml/types/container_test.go | 38 +++--- pipeline/frontend/yaml/types/ulimit.go | 97 -------------- pipeline/frontend/yaml/types/ulimit_test.go | 126 ------------------ 4 files changed, 30 insertions(+), 266 deletions(-) delete mode 100644 pipeline/frontend/yaml/types/ulimit.go delete mode 100644 pipeline/frontend/yaml/types/ulimit_test.go diff --git a/pipeline/frontend/yaml/types/container.go b/pipeline/frontend/yaml/types/container.go index 84d90d4ff..4eac437da 100644 --- a/pipeline/frontend/yaml/types/container.go +++ b/pipeline/frontend/yaml/types/container.go @@ -38,26 +38,21 @@ type ( Privileged bool `yaml:"privileged,omitempty"` // Undocumented - CapAdd []string `yaml:"cap_add,omitempty"` - CapDrop []string `yaml:"cap_drop,omitempty"` - CPUQuota base.StringOrInt `yaml:"cpu_quota,omitempty"` - CPUSet string `yaml:"cpuset,omitempty"` - CPUShares base.StringOrInt `yaml:"cpu_shares,omitempty"` - Devices []string `yaml:"devices,omitempty"` - DNSSearch base.StringOrSlice `yaml:"dns_search,omitempty"` - DNS base.StringOrSlice `yaml:"dns,omitempty"` - ExtraHosts []string `yaml:"extra_hosts,omitempty"` - IpcMode string `yaml:"ipc_mode,omitempty"` - Isolation string `yaml:"isolation,omitempty"` - MemLimit base.MemStringOrInt `yaml:"mem_limit,omitempty"` - MemSwapLimit base.MemStringOrInt `yaml:"memswap_limit,omitempty"` - MemSwappiness base.MemStringOrInt `yaml:"mem_swappiness,omitempty"` - NetworkMode string `yaml:"network_mode,omitempty"` - Networks Networks `yaml:"networks,omitempty"` - ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"` - Sysctls base.SliceOrMap `yaml:"sysctls,omitempty"` - Tmpfs []string `yaml:"tmpfs,omitempty"` - Ulimits Ulimits `yaml:"ulimits,omitempty"` + CPUQuota base.StringOrInt `yaml:"cpu_quota,omitempty"` + CPUSet string `yaml:"cpuset,omitempty"` + CPUShares base.StringOrInt `yaml:"cpu_shares,omitempty"` + Devices []string `yaml:"devices,omitempty"` + DNSSearch base.StringOrSlice `yaml:"dns_search,omitempty"` + DNS base.StringOrSlice `yaml:"dns,omitempty"` + ExtraHosts []string `yaml:"extra_hosts,omitempty"` + IpcMode string `yaml:"ipc_mode,omitempty"` + MemLimit base.MemStringOrInt `yaml:"mem_limit,omitempty"` + MemSwapLimit base.MemStringOrInt `yaml:"memswap_limit,omitempty"` + NetworkMode string `yaml:"network_mode,omitempty"` + Networks Networks `yaml:"networks,omitempty"` + ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"` + Sysctls base.SliceOrMap `yaml:"sysctls,omitempty"` + Tmpfs []string `yaml:"tmpfs,omitempty"` } ) diff --git a/pipeline/frontend/yaml/types/container_test.go b/pipeline/frontend/yaml/types/container_test.go index 9ebbbdcc1..b3755a985 100644 --- a/pipeline/frontend/yaml/types/container_test.go +++ b/pipeline/frontend/yaml/types/container_test.go @@ -13,8 +13,6 @@ import ( var containerYaml = []byte(` image: golang:latest -cap_add: [ ALL ] -cap_drop: [ NET_ADMIN, SYS_ADMIN ] commands: - go build - go test @@ -33,7 +31,6 @@ environment: extra_hosts: - somehost:162.242.195.82 - otherhost:50.31.209.229 -isolation: hyperv name: my-build-container network_mode: bridge networks: @@ -44,7 +41,6 @@ privileged: true shm_size: 1kb mem_limit: 1kb memswap_limit: 1kb -mem_swappiness: 1kb volumes: - /var/lib/mysql - /opt/data:/var/lib/mysql @@ -62,25 +58,21 @@ settings: func TestUnmarshalContainer(t *testing.T) { want := Container{ - CapAdd: []string{"ALL"}, - CapDrop: []string{"NET_ADMIN", "SYS_ADMIN"}, - Commands: base.StringOrSlice{"go build", "go test"}, - CPUQuota: base.StringOrInt(11), - CPUSet: "1,2", - CPUShares: base.StringOrInt(99), - Detached: true, - Devices: []string{"/dev/ttyUSB0:/dev/ttyUSB0"}, - Directory: "example/", - DNS: base.StringOrSlice{"8.8.8.8"}, - DNSSearch: base.StringOrSlice{"example.com"}, - Environment: base.SliceOrMap{"RACK_ENV": "development", "SHOW": "true"}, - ExtraHosts: []string{"somehost:162.242.195.82", "otherhost:50.31.209.229"}, - Image: "golang:latest", - Isolation: "hyperv", - MemLimit: base.MemStringOrInt(1024), - MemSwapLimit: base.MemStringOrInt(1024), - MemSwappiness: base.MemStringOrInt(1024), - Name: "my-build-container", + Commands: base.StringOrSlice{"go build", "go test"}, + CPUQuota: base.StringOrInt(11), + CPUSet: "1,2", + CPUShares: base.StringOrInt(99), + Detached: true, + Devices: []string{"/dev/ttyUSB0:/dev/ttyUSB0"}, + Directory: "example/", + DNS: base.StringOrSlice{"8.8.8.8"}, + DNSSearch: base.StringOrSlice{"example.com"}, + Environment: base.SliceOrMap{"RACK_ENV": "development", "SHOW": "true"}, + ExtraHosts: []string{"somehost:162.242.195.82", "otherhost:50.31.209.229"}, + Image: "golang:latest", + MemLimit: base.MemStringOrInt(1024), + MemSwapLimit: base.MemStringOrInt(1024), + Name: "my-build-container", Networks: Networks{ Networks: []*Network{ {Name: "some-network"}, diff --git a/pipeline/frontend/yaml/types/ulimit.go b/pipeline/frontend/yaml/types/ulimit.go deleted file mode 100644 index caaac9888..000000000 --- a/pipeline/frontend/yaml/types/ulimit.go +++ /dev/null @@ -1,97 +0,0 @@ -package types - -import ( - "errors" - "fmt" - "sort" -) - -// Ulimits represents a list of Ulimit. -// It is, however, represented in yaml as keys (and thus map in Go) -type Ulimits struct { - Elements []Ulimit -} - -// MarshalYAML implements the Marshaller interface. -func (u Ulimits) MarshalYAML() (interface{}, error) { - ulimitMap := make(map[string]Ulimit) - for _, ulimit := range u.Elements { - ulimitMap[ulimit.Name] = ulimit - } - return ulimitMap, nil -} - -// UnmarshalYAML implements the Unmarshaler interface. -func (u *Ulimits) UnmarshalYAML(unmarshal func(interface{}) error) error { - ulimits := make(map[string]Ulimit) - - var mapType map[interface{}]interface{} - if err := unmarshal(&mapType); err == nil { - for mapKey, mapValue := range mapType { - name, ok := mapKey.(string) - if !ok { - return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) - } - var soft, hard int64 - switch mv := mapValue.(type) { - case int: - soft = int64(mv) - hard = int64(mv) - case map[string]interface{}: - if len(mv) != 2 { - return fmt.Errorf("Failed to unmarshal Ulimit: %#v", mapValue) - } - for mkey, mvalue := range mv { - switch mkey { - case "soft": - soft = int64(mvalue.(int)) - case "hard": - hard = int64(mvalue.(int)) - default: - // FIXME(vdemeester) Should we ignore or fail ? - continue - } - } - default: - return fmt.Errorf("Failed to unmarshal Ulimit: %v, %T", mapValue, mapValue) - } - ulimits[name] = Ulimit{ - Name: name, - ulimitValues: ulimitValues{ - Soft: soft, - Hard: hard, - }, - } - } - keys := make([]string, 0, len(ulimits)) - for key := range ulimits { - keys = append(keys, key) - } - sort.Strings(keys) - for _, key := range keys { - u.Elements = append(u.Elements, ulimits[key]) - } - return nil - } - - return errors.New("Failed to unmarshal Ulimit") -} - -// Ulimit represents ulimit information. -type Ulimit struct { - ulimitValues - Name string -} - -type ulimitValues struct { - Soft int64 `yaml:"soft"` - Hard int64 `yaml:"hard"` -} - -// MarshalYAML implements the Marshaller interface. -func (u Ulimit) MarshalYAML() (interface{}, error) { - if u.Soft == u.Hard { - return u.Soft, nil - } - return u.ulimitValues, nil -} diff --git a/pipeline/frontend/yaml/types/ulimit_test.go b/pipeline/frontend/yaml/types/ulimit_test.go deleted file mode 100644 index f9396fb8b..000000000 --- a/pipeline/frontend/yaml/types/ulimit_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package types - -import ( - "testing" - - "gopkg.in/yaml.v3" - - "github.com/stretchr/testify/assert" -) - -func TestMarshalUlimit(t *testing.T) { - ulimits := []struct { - ulimits *Ulimits - expected string - }{ - { - ulimits: &Ulimits{ - Elements: []Ulimit{ - { - ulimitValues: ulimitValues{ - Soft: 65535, - Hard: 65535, - }, - Name: "nstep", - }, - }, - }, - expected: `nstep: 65535 -`, - }, - { - ulimits: &Ulimits{ - Elements: []Ulimit{ - { - Name: "nofile", - ulimitValues: ulimitValues{ - Soft: 20000, - Hard: 40000, - }, - }, - }, - }, - expected: `nofile: - soft: 20000 - hard: 40000 -`, - }, - } - - for _, ulimit := range ulimits { - bytes, err := yaml.Marshal(ulimit.ulimits) - - assert.Nil(t, err) - assert.Equal(t, ulimit.expected, string(bytes), "should be equal") - } -} - -func TestUnmarshalUlimits(t *testing.T) { - ulimits := []struct { - yaml string - expected *Ulimits - }{ - { - yaml: "nstep: 65535", - expected: &Ulimits{ - Elements: []Ulimit{ - { - Name: "nstep", - ulimitValues: ulimitValues{ - Soft: 65535, - Hard: 65535, - }, - }, - }, - }, - }, - { - yaml: `nofile: - soft: 20000 - hard: 40000`, - expected: &Ulimits{ - Elements: []Ulimit{ - { - Name: "nofile", - ulimitValues: ulimitValues{ - Soft: 20000, - Hard: 40000, - }, - }, - }, - }, - }, - { - yaml: `nstep: 65535 -nofile: - soft: 20000 - hard: 40000`, - expected: &Ulimits{ - Elements: []Ulimit{ - { - Name: "nofile", - ulimitValues: ulimitValues{ - Soft: 20000, - Hard: 40000, - }, - }, - { - Name: "nstep", - ulimitValues: ulimitValues{ - Soft: 65535, - Hard: 65535, - }, - }, - }, - }, - }, - } - - for _, ulimit := range ulimits { - actual := &Ulimits{} - err := yaml.Unmarshal([]byte(ulimit.yaml), actual) - - assert.Nil(t, err) - assert.Equal(t, ulimit.expected, actual, "should be equal") - } -}