Skip to content

Commit

Permalink
Merge pull request #1789 from alexandear/refactor-map-init
Browse files Browse the repository at this point in the history
Refactor map init with short declaration syntax
  • Loading branch information
openshift-merge-bot[bot] authored Jan 8, 2024
2 parents c9272ca + 2f131ee commit 40bc472
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 35 deletions.
5 changes: 2 additions & 3 deletions internal/attributedstring/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ func (a *Slice) MarshalTOML() ([]byte, error) {
}

if a.Attributes.Append != nil {
Attributes := make(map[string]any)
Attributes["append"] = *a.Attributes.Append
iFaceSlice = append(iFaceSlice, Attributes)
attributes := map[string]any{"append": *a.Attributes.Append}
iFaceSlice = append(iFaceSlice, attributes)
}

buf := new(bytes.Buffer)
Expand Down
3 changes: 1 addition & 2 deletions libimage/manifest_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func TestInspectManifestListWithAnnotations(t *testing.T) {
require.NoError(t, err)

annotateOptions := ManifestListAnnotateOptions{}
annotations := make(map[string]string)
annotations["hello"] = "world"
annotations := map[string]string{"hello": "world"}
annotateOptions.Annotations = annotations

err = list.AnnotateInstance(digest, &annotateOptions)
Expand Down
15 changes: 4 additions & 11 deletions libnetwork/cni/cni_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ func newNcList(name, version string, labels, options map[string]string) ncList {

// newHostLocalBridge creates a new LocalBridge for host-local
func newHostLocalBridge(name string, isGateWay, ipMasq bool, mtu, vlan int, ipamConf *ipamConfig) *hostLocalBridge {
caps := make(map[string]bool)
caps["ips"] = true
bridge := hostLocalBridge{
PluginType: "bridge",
BrName: name,
Expand All @@ -153,7 +151,7 @@ func newHostLocalBridge(name string, isGateWay, ipMasq bool, mtu, vlan int, ipam
bridge.IPAM = *ipamConf
// if we use host-local set the ips cap to ensure we can set static ips via runtime config
if ipamConf.PluginType == types.HostLocalIPAMDriver {
bridge.Capabilities = caps
bridge.Capabilities = map[string]bool{"ips": true}
}
}
return &bridge
Expand Down Expand Up @@ -215,13 +213,10 @@ func newIPAMDefaultRoute(isIPv6 bool) (ipamRoute, error) {
// newPortMapPlugin creates a predefined, default portmapping
// configuration
func newPortMapPlugin() portMapConfig {
caps := make(map[string]bool)
caps["portMappings"] = true
p := portMapConfig{
return portMapConfig{
PluginType: "portmap",
Capabilities: caps,
Capabilities: map[string]bool{"portMappings": true},
}
return p
}

// newFirewallPlugin creates a generic firewall plugin
Expand All @@ -245,12 +240,10 @@ func newTuningPlugin() tuningConfig {
// newDNSNamePlugin creates the dnsname config with a given
// domainname
func newDNSNamePlugin(domainName string) dnsNameConfig {
caps := make(map[string]bool, 1)
caps["aliases"] = true
return dnsNameConfig{
PluginType: "dnsname",
DomainName: domainName,
Capabilities: caps,
Capabilities: map[string]bool{"aliases": true},
}
}

Expand Down
5 changes: 3 additions & 2 deletions libnetwork/cni/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
// If we have more than one static ip we need parse the ips via runtime config,
// make sure to add the ips capability to the first plugin otherwise it doesn't get the ips
if len(netOpts.StaticIPs) > 0 && !network.cniNet.Plugins[0].Network.Capabilities["ips"] {
caps := make(map[string]interface{})
caps["capabilities"] = map[string]bool{"ips": true}
caps := map[string]interface{}{
"capabilities": map[string]bool{"ips": true},
}
network.cniNet.Plugins[0], retErr = libcni.InjectConf(network.cniNet.Plugins[0], caps)
if retErr != nil {
return retErr
Expand Down
13 changes: 7 additions & 6 deletions pkg/cgroups/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ const (
var handlers map[string]controllerHandler

func init() {
handlers = make(map[string]controllerHandler)
handlers[CPU] = getCPUHandler()
handlers[CPUset] = getCpusetHandler()
handlers[Memory] = getMemoryHandler()
handlers[Pids] = getPidsHandler()
handlers[Blkio] = getBlkioHandler()
handlers = map[string]controllerHandler{
CPU: getCPUHandler(),
CPUset: getCpusetHandler(),
Memory: getMemoryHandler(),
Pids: getPidsHandler(),
Blkio: getBlkioHandler(),
}
}

// getAvailableControllers get the available controllers
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ func defaultMachineConfig() MachineConfig {

// defaultFarmConfig returns the default farms configuration.
func defaultFarmConfig() FarmConfig {
emptyList := make(map[string][]string)
return FarmConfig{
List: emptyList,
List: map[string][]string{},
}
}

Expand Down
14 changes: 5 additions & 9 deletions pkg/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ func setup(t *testing.T) (manager *SecretsManager, opts map[string]string) {
func TestAddSecretAndLookupData(t *testing.T) {
manager, opts := setup(t)

metaData := make(map[string]string)
metaData["immutable"] = "true"

labels := make(map[string]string)
labels["foo"] = "bar"
labels["another"] = "label"

storeOpts := StoreOptions{
DriverOpts: opts,
Metadata: metaData,
Labels: labels,
Metadata: map[string]string{"immutable": "true"},
Labels: map[string]string{
"foo": "bar",
"another": "label",
},
}

id1, err := manager.Store("mysecret", []byte("mydata"), drivertype, storeOpts)
Expand Down

0 comments on commit 40bc472

Please sign in to comment.