-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4366 from 0x0034/fix/useClusterConfigurationGetCIDR
fix: fail to get podCIDR and serviceCIDR Signed-off-by: robot <[email protected]>
- Loading branch information
1 parent
dfc289e
commit 36d780f
Showing
6 changed files
with
164 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package coordinatormanager | ||
|
||
import ( | ||
"encoding/json" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var _ = Describe("Coordinator Manager", Label("coordinatorinformer", "informer_test"), Serial, func() { | ||
DescribeTable("should extract CIDRs correctly", | ||
func(testName, cmStr string, expectedPodCIDR, expectedServiceCIDR []string, expectError bool) { | ||
var cm corev1.ConfigMap | ||
err := json.Unmarshal([]byte(cmStr), &cm) | ||
Expect(err).NotTo(HaveOccurred(), "Failed to unmarshal configMap: %v\n", err) | ||
|
||
podCIDR, serviceCIDR, err := ExtractK8sCIDRFromKubeadmConfigMap(&cm) | ||
|
||
if expectError { | ||
Expect(err).To(HaveOccurred(), "Expected an error but got none") | ||
} else { | ||
Expect(err).NotTo(HaveOccurred(), "Did not expect an error but got one: %v", err) | ||
} | ||
|
||
Expect(podCIDR).To(Equal(expectedPodCIDR), "Pod CIDR does not match") | ||
Expect(serviceCIDR).To(Equal(expectedServiceCIDR), "Service CIDR does not match") | ||
}, | ||
Entry("ClusterConfiguration", | ||
"ClusterConfiguration", | ||
clusterConfigurationJson, | ||
[]string{"192.168.165.0/24"}, | ||
[]string{"245.100.128.0/18"}, | ||
false, | ||
), | ||
Entry("No ClusterConfiguration", | ||
"No ClusterConfiguration", | ||
noClusterConfigurationJson, | ||
nil, | ||
nil, | ||
true, | ||
), | ||
Entry("No CIDR", | ||
"No CIDR", | ||
noCIDRJson, | ||
nil, | ||
nil, | ||
false, | ||
), | ||
) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package coordinatormanager | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var ( | ||
clusterConfigurationJson string | ||
noClusterConfigurationJson string | ||
noCIDRJson string | ||
) | ||
|
||
func TestCoordinatorManager(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "CoordinatorManager Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
clusterConfigurationJson = ` | ||
{ | ||
"apiVersion": "v1", | ||
"data": { | ||
"ClusterConfiguration": "networking:\n dnsDomain: cluster.local\n podSubnet: 192.168.165.0/24\n serviceSubnet: 245.100.128.0/18" | ||
}, | ||
"kind": "ConfigMap", | ||
"metadata": { | ||
"name": "kubeadm-config", | ||
"namespace": "kube-system" | ||
} | ||
}` | ||
noClusterConfigurationJson = ` | ||
{ | ||
"apiVersion": "v1", | ||
"data": { | ||
"ClusterStatus": "apiEndpoints:\n anolios79:\n advertiseAddress: 192.168.165.128\n bindPort: 6443\napiVersion: kubeadm.k8s.io/v1beta2\nkind: ClusterStatus\n" | ||
}, | ||
"kind": "ConfigMap", | ||
"metadata": { | ||
"name": "kubeadm-config", | ||
"namespace": "kube-system" | ||
} | ||
}` | ||
noCIDRJson = ` | ||
{ | ||
"apiVersion": "v1", | ||
"data": { | ||
"ClusterConfiguration": "clusterName: spider\ncontrolPlaneEndpoint: spider-control-plane:6443\ncontrollerManager:\n" | ||
}, | ||
"kind": "ConfigMap", | ||
"metadata": { | ||
"name": "kubeadm-config", | ||
"namespace": "kube-system" | ||
} | ||
}` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters