-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assigned egress ips into capacity
This makes sure capacity field in cloud.network.openshift.io/egress-ipconfig node annotation (which is introduced in 4.10) denotes correct value when cluster upgrade happens for example 4.9 to 4.10 and node is already assigned with egress ips. Signed-off-by: Periyasamy Palanisamy <pepalani@redhat.com> (cherry picked from commit 8ffb0c1) (cherry picked from commit bfe1601)
- Loading branch information
1 parent
be8d44c
commit b7e0f63
Showing
11 changed files
with
159 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cloudprivateipconfig | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"strings" | ||
) | ||
|
||
// IPFamily string representing ip family | ||
type IPFamily string | ||
|
||
const ( | ||
// IPv4 IPFamily constant ipv4 family | ||
IPv4 IPFamily = "ipv4" | ||
// IPv6 IPFamily constant ipv6 family | ||
IPv6 IPFamily = "ipv6" | ||
) | ||
|
||
// NameToIP converts the resource name to net.IP. Given a | ||
// limitation in the Kubernetes API server (see: | ||
// https://github.com/kubernetes/kubernetes/pull/100950) | ||
// CloudPrivateIPConfig.metadata.name cannot represent an IPv6 address. To | ||
// work-around this limitation it was decided that the network plugin creating | ||
// the CR will fully expand the IPv6 address and replace all colons with dots, | ||
// Example: The IPv6 address fc00:f853:ccd:e793::54 will be represented | ||
// as: fc00.f853.0ccd.e793.0000.0000.0000.0054, We thus need to replace | ||
// every fifth character's dot with a colon. | ||
func NameToIP(name string) (net.IP, IPFamily, error) { | ||
// handle IPv4: this is enough since it will be serialized just fine | ||
if ip := net.ParseIP(name); ip != nil { | ||
return ip, IPv4, nil | ||
} | ||
// handle IPv6 | ||
name = strings.ReplaceAll(name, ".", ":") | ||
if ip := net.ParseIP(name); ip != nil { | ||
return ip, IPv6, nil | ||
} | ||
return nil, "", errors.New("invalid ip family") | ||
} |
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,33 @@ | ||
package cloudprivateipconfig | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCloudPrivateIPConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Test CloudPrivateIPConfig") | ||
} | ||
|
||
var _ = Describe("CloudPrivateIPConfig", func() { | ||
Context("Validate Name to IP", func() { | ||
It("With valid names", func() { | ||
ip, family, err := NameToIP("192.168.0.10") | ||
Expect(err).To(BeNil()) | ||
Expect(ip.String()).To(Equal(("192.168.0.10"))) | ||
Expect(family).To(Equal(IPv4)) | ||
ip, family, err = NameToIP("fc00.f853.0ccd.e793.0000.0000.0000.0054") | ||
Expect(err).To(BeNil()) | ||
Expect(ip.String()).To(Equal(("fc00:f853:ccd:e793::54"))) | ||
Expect(family).To(Equal(IPv6)) | ||
}) | ||
It("With invalid name", func() { | ||
_, _, err := NameToIP("invalid_config") | ||
Expect(err).NotTo(BeNil()) | ||
}) | ||
}) | ||
|
||
}) |
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
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
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
Oops, something went wrong.