Skip to content

Commit

Permalink
Merge pull request #2544 from ty-dc/cleanup/remove-default
Browse files Browse the repository at this point in the history
cleanup: remove configmap obsolete fields
  • Loading branch information
cyclinder authored Nov 6, 2023
2 parents cb483ff + 8bd07b9 commit d859620
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 95 deletions.
18 changes: 7 additions & 11 deletions cmd/spiderpool-agent/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ type Config struct {
MultusClusterNetwork string

// configmap
IpamUnixSocketPath string `yaml:"ipamUnixSocketPath"`
EnableIPv4 bool `yaml:"enableIPv4"`
EnableIPv6 bool `yaml:"enableIPv6"`
EnableStatefulSet bool `yaml:"enableStatefulSet"`
EnableKubevirtStaticIP bool `yaml:"enableKubevirtStaticIP"`
EnableSpiderSubnet bool `yaml:"enableSpiderSubnet"`
ClusterDefaultIPv4IPPool []string `yaml:"clusterDefaultIPv4IPPool"`
ClusterDefaultIPv6IPPool []string `yaml:"clusterDefaultIPv6IPPool"`
ClusterDefaultIPv4Subnet []string `yaml:"clusterDefaultIPv4Subnet"`
ClusterDefaultIPv6Subnet []string `yaml:"clusterDefaultIPv6Subnet"`
ClusterSubnetDefaultFlexibleIPNum int `yaml:"clusterSubnetDefaultFlexibleIPNumber"`
IpamUnixSocketPath string `yaml:"ipamUnixSocketPath"`
EnableIPv4 bool `yaml:"enableIPv4"`
EnableIPv6 bool `yaml:"enableIPv6"`
EnableStatefulSet bool `yaml:"enableStatefulSet"`
EnableKubevirtStaticIP bool `yaml:"enableKubevirtStaticIP"`
EnableSpiderSubnet bool `yaml:"enableSpiderSubnet"`
ClusterSubnetDefaultFlexibleIPNum int `yaml:"clusterSubnetDefaultFlexibleIPNumber"`
}

type AgentContext struct {
Expand Down
16 changes: 7 additions & 9 deletions cmd/spiderpool-agent/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ func DaemonMain() {

logger.Info("Begin to initialize IPAM")
ipamConfig := ipam.IPAMConfig{
EnableIPv4: agentContext.Cfg.EnableIPv4,
EnableIPv6: agentContext.Cfg.EnableIPv6,
ClusterDefaultIPv4IPPool: agentContext.Cfg.ClusterDefaultIPv4IPPool,
ClusterDefaultIPv6IPPool: agentContext.Cfg.ClusterDefaultIPv6IPPool,
EnableSpiderSubnet: agentContext.Cfg.EnableSpiderSubnet,
EnableStatefulSet: agentContext.Cfg.EnableStatefulSet,
EnableKubevirtStaticIP: agentContext.Cfg.EnableKubevirtStaticIP,
OperationRetries: agentContext.Cfg.WaitSubnetPoolMaxRetries,
OperationGapDuration: time.Duration(agentContext.Cfg.WaitSubnetPoolTime) * time.Second,
EnableIPv4: agentContext.Cfg.EnableIPv4,
EnableIPv6: agentContext.Cfg.EnableIPv6,
EnableSpiderSubnet: agentContext.Cfg.EnableSpiderSubnet,
EnableStatefulSet: agentContext.Cfg.EnableStatefulSet,
EnableKubevirtStaticIP: agentContext.Cfg.EnableKubevirtStaticIP,
OperationRetries: agentContext.Cfg.WaitSubnetPoolMaxRetries,
OperationGapDuration: time.Duration(agentContext.Cfg.WaitSubnetPoolTime) * time.Second,
}
if len(agentContext.Cfg.MultusClusterNetwork) != 0 {
ipamConfig.MultusClusterNetwork = pointer.String(agentContext.Cfg.MultusClusterNetwork)
Expand Down
6 changes: 2 additions & 4 deletions pkg/ipam/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
)

type IPAMConfig struct {
EnableIPv4 bool
EnableIPv6 bool
ClusterDefaultIPv4IPPool []string
ClusterDefaultIPv6IPPool []string
EnableIPv4 bool
EnableIPv6 bool

EnableSpiderSubnet bool
EnableStatefulSet bool
Expand Down
35 changes: 0 additions & 35 deletions test/e2e/common/spiderpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import (
. "github.com/onsi/gomega"
frame "github.com/spidernet-io/e2eframework/framework"
"github.com/spidernet-io/e2eframework/tools"
"github.com/spidernet-io/spiderpool/cmd/spiderpool-agent/cmd"
"github.com/spidernet-io/spiderpool/pkg/constant"
ip "github.com/spidernet-io/spiderpool/pkg/ip"
"github.com/spidernet-io/spiderpool/pkg/types"

"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
api_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -310,39 +308,6 @@ func CheckPodIpRecordInIppool(f *frame.Framework, v4IppoolNameList, v6IppoolName
}
}

func GetClusterDefaultIppool(f *frame.Framework) (v4IppoolList, v6IppoolList []string, e error) {
if f == nil {
return nil, nil, errors.New("wrong input")
}

configMap, e := f.GetConfigmap(SpiderPoolConfigmapName, SpiderPoolConfigmapNameSpace)
if e != nil {
return nil, nil, e
}
GinkgoWriter.Printf("configmap: %+v \n", configMap.Data)

data, ok := configMap.Data["conf.yml"]
if !ok || len(data) == 0 {
return nil, nil, errors.New("failed to find cluster default ippool")
}

conf := cmd.Config{}
if err := yaml.Unmarshal([]byte(data), &conf); nil != err {
GinkgoWriter.Printf("failed to decode yaml config: %v \n", data)
return nil, nil, errors.New("failed to find cluster default ippool")
}
GinkgoWriter.Printf("yaml config: %v \n", conf)

if conf.EnableIPv4 && len(conf.ClusterDefaultIPv4IPPool) == 0 {
return nil, nil, errors.New("IPv4 IPPool is not specified when IPv4 is enabled")
}
if conf.EnableIPv6 && len(conf.ClusterDefaultIPv6IPPool) == 0 {
return nil, nil, errors.New("IPv6 IPPool is not specified when IPv6 is enabled")
}

return conf.ClusterDefaultIPv4IPPool, conf.ClusterDefaultIPv6IPPool, nil
}

func GetNamespaceDefaultIppool(f *frame.Framework, namespace string) (v4IppoolList, v6IppoolList []string, e error) {
ns, err := f.GetNamespace(namespace)
if err != nil {
Expand Down
35 changes: 0 additions & 35 deletions test/e2e/common/spidersubnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import (
"time"

. "github.com/onsi/gomega"
"github.com/spidernet-io/spiderpool/cmd/spiderpool-agent/cmd"
"github.com/spidernet-io/spiderpool/pkg/constant"
"github.com/spidernet-io/spiderpool/pkg/lock"
"github.com/spidernet-io/spiderpool/pkg/utils/convert"
"gopkg.in/yaml.v3"

ip "github.com/spidernet-io/spiderpool/pkg/ip"
spiderpool "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
Expand Down Expand Up @@ -445,39 +443,6 @@ OUTER_FOR:
return subnetNameList, nil
}

func GetClusterDefaultSubnet(f *frame.Framework) (v4SubnetList, v6SubnetList []string, e error) {
if f == nil {
return nil, nil, errors.New("wrong input")
}

configMap, e := f.GetConfigmap(SpiderPoolConfigmapName, SpiderPoolConfigmapNameSpace)
if e != nil {
return nil, nil, e
}
GinkgoWriter.Printf("configmap: %+v \n", configMap.Data)

data, ok := configMap.Data["conf.yml"]
if !ok || len(data) == 0 {
return nil, nil, errors.New("failed to find cluster default subnet")
}

conf := cmd.Config{}
if err := yaml.Unmarshal([]byte(data), &conf); nil != err {
GinkgoWriter.Printf("failed to decode yaml config: %v \n", data)
return nil, nil, errors.New("failed to find cluster default subnet")
}
GinkgoWriter.Printf("yaml config: %v \n", conf)

if conf.EnableIPv4 && len(conf.ClusterDefaultIPv4Subnet) != 0 {
v4SubnetList = conf.ClusterDefaultIPv4Subnet
}
if conf.EnableIPv6 && len(conf.ClusterDefaultIPv6Subnet) != 0 {
v6SubnetList = conf.ClusterDefaultIPv6Subnet
}

return v4SubnetList, v6SubnetList, nil
}

func GetAllSubnet(f *frame.Framework, opts ...client.ListOption) (*spiderpool.SpiderSubnetList, error) {
if f == nil {
return nil, errors.New("wrong input")
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/subnet/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,8 @@ var _ = Describe("test subnet", Label("subnet"), func() {
// Get the default subnet
// and verify that the default subnet functions properly
By("get cluster default subnet")
ClusterDefaultV4SubnetList, ClusterDefaultV6SubnetList, err = common.GetClusterDefaultSubnet(frame)
// TODO(ty-dc), Default subnet to be determined for now
// ClusterDefaultV4SubnetList, ClusterDefaultV6SubnetList, err = common.GetClusterDefaultSubnet(frame)
Expect(err).NotTo(HaveOccurred())
if frame.Info.IpV4Enabled && len(ClusterDefaultV4SubnetList) == 0 {
Skip("v4 Default Subnet function is not enabled")
Expand Down

0 comments on commit d859620

Please sign in to comment.