-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/v1.45] Improvements for Anexia (#1405)
* Make anexia provider more resilient against errors (#1175) * add conditions & tests Original commit by @kstiehl, conflicts resolved by @LittleFox94, mainly in pkg/cloudprovider/provider/anexia/provider.go Signed-off-by: kstiehl <kevin.stiehl@numericas.de> Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Fix various linter errors Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Add missing boilerplate to files Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Anexia provider: add dummy updater for tests Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> Co-authored-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * docs(anexia): add info for templates (#1288) * docs(anexia): add info for templates Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com> * Update anexia.md Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com> * anexia: increase HTTP client timeout to 120s (#1331) Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Anexia: extend disk configuration (#1402) * Anexia: cleanup Config/RawConfig attribute duplication types.Config and types.RawConfig contained the same members, with RawConfig using ConfigVars and Config storing the resolved data. This commit does some cleanup to ease adding new config values in the future. Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Anexia: extend disk configuration Adds a new config value "Disks", with each entry configuring the size and performance type of a single disk. The config format can be used for configuring multiple disks in the future, which is on our roadmap, but right now only a single disk is supported - with the added feature of defining the performance type. Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Anexia: update MachineDeployment example Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * CI: disable OperationSystemManager for Anexia Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> * Anexia: return reserved IP when instance IPs are requested When creating a machine at, we always first reserve an IP address for it. Later when retrieving the addresses of that machine, we rely on the vminfo API, which has some delay as it retrieves the IPs from the running VM. This commit adds the reserved address to the list of addresses returned from an instance, which should reduce provisioning time a bit and make it more stable. Also fixes a long-standing TODO comment: marking internal IPs as internal. Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com> Signed-off-by: Mara Sophie Grosch <mgrosch@anexia-it.com> Co-authored-by: Kevin Stiehl <kevinstiehl@live.de> Co-authored-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
- Loading branch information
1 parent
81dc767
commit 4285d57
Showing
12 changed files
with
1,167 additions
and
164 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
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,91 @@ | ||
/* | ||
Copyright 2022 The Machine Controller Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package anexia | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/anexia-it/go-anxcloud/pkg/vsphere/search" | ||
"github.com/gophercloud/gophercloud/testhelper" | ||
"github.com/kubermatic/machine-controller/pkg/apis/cluster/v1alpha1" | ||
anxtypes "github.com/kubermatic/machine-controller/pkg/cloudprovider/provider/anexia/types" | ||
"github.com/kubermatic/machine-controller/pkg/providerconfig/types" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
type ConfigTestCase struct { | ||
Config anxtypes.RawConfig | ||
Error error | ||
} | ||
|
||
type ValidateCallTestCase struct { | ||
Spec v1alpha1.MachineSpec | ||
ExpectedError error | ||
} | ||
|
||
func getSpecsForValidationTest(t *testing.T, configCases []ConfigTestCase) []ValidateCallTestCase { | ||
|
||
var testCases []ValidateCallTestCase | ||
|
||
for _, configCase := range configCases { | ||
jsonConfig, err := json.Marshal(configCase.Config) | ||
testhelper.AssertNoErr(t, err) | ||
jsonProviderConfig, err := json.Marshal(types.Config{ | ||
CloudProviderSpec: runtime.RawExtension{Raw: jsonConfig}, | ||
OperatingSystemSpec: runtime.RawExtension{Raw: []byte("{}")}, | ||
}) | ||
testhelper.AssertNoErr(t, err) | ||
testCases = append(testCases, ValidateCallTestCase{ | ||
Spec: v1alpha1.MachineSpec{ | ||
ProviderSpec: v1alpha1.ProviderSpec{ | ||
Value: &runtime.RawExtension{Raw: jsonProviderConfig}, | ||
}, | ||
}, | ||
ExpectedError: configCase.Error, | ||
}) | ||
} | ||
return testCases | ||
} | ||
|
||
func createSearchHandler(t *testing.T, iterations int) http.HandlerFunc { | ||
counter := 0 | ||
return func(writer http.ResponseWriter, request *http.Request) { | ||
test := request.URL.Query().Get("name") | ||
testhelper.AssertEquals(t, "%-TestMachine", test) | ||
testhelper.TestMethod(t, request, http.MethodGet) | ||
if iterations == counter { | ||
encoder := json.NewEncoder(writer) | ||
testhelper.AssertNoErr(t, encoder.Encode(map[string]interface{}{ | ||
"data": []search.VM{ | ||
{ | ||
Name: "543053-TestMachine", | ||
Identifier: TestIdentifier, | ||
}, | ||
}, | ||
})) | ||
} | ||
counter++ | ||
} | ||
} | ||
|
||
func newConfigVarString(str string) types.ConfigVarString { | ||
return types.ConfigVarString{ | ||
Value: str, | ||
} | ||
} |
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,127 @@ | ||
/* | ||
Copyright 2022 The Machine Controller Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package anexia | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gophercloud/gophercloud/testhelper" | ||
|
||
"github.com/anexia-it/go-anxcloud/pkg/vsphere/info" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestAnexiaInstance(t *testing.T) { | ||
addressCheck := func(t *testing.T, testcase string, instance *anexiaInstance, expected map[string]v1.NodeAddressType) { | ||
t.Run(testcase, func(t *testing.T) { | ||
addresses := instance.Addresses() | ||
|
||
testhelper.AssertDeepEquals(t, expected, addresses) | ||
}) | ||
} | ||
|
||
t.Run("empty instance", func(t *testing.T) { | ||
instance := anexiaInstance{} | ||
addressCheck(t, "no addresses", &instance, map[string]v1.NodeAddressType{}) | ||
}) | ||
|
||
t.Run("instance with only reservedAddresses set", func(t *testing.T) { | ||
instance := anexiaInstance{ | ||
reservedAddresses: []string{"10.0.0.2", "fda0:23::2", "8.8.8.8", "2001:db8::2"}, | ||
} | ||
|
||
addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{ | ||
"10.0.0.2": v1.NodeInternalIP, | ||
"fda0:23::2": v1.NodeInternalIP, | ||
"8.8.8.8": v1.NodeExternalIP, | ||
"2001:db8::2": v1.NodeExternalIP, | ||
}) | ||
}) | ||
|
||
t.Run("instance with only info set", func(t *testing.T) { | ||
instance := anexiaInstance{ | ||
info: &info.Info{ | ||
Network: []info.Network{ | ||
{ | ||
IPv4: []string{"10.0.0.2"}, | ||
IPv6: []string{"fda0:23::2"}, | ||
}, | ||
{ | ||
IPv4: []string{"8.8.8.8"}, | ||
IPv6: []string{"2001:db8::2"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{ | ||
"10.0.0.2": v1.NodeInternalIP, | ||
"fda0:23::2": v1.NodeInternalIP, | ||
"8.8.8.8": v1.NodeExternalIP, | ||
"2001:db8::2": v1.NodeExternalIP, | ||
}) | ||
}) | ||
|
||
t.Run("instance with both reservedAddresses and info set, full overlapping set", func(t *testing.T) { | ||
instance := anexiaInstance{ | ||
reservedAddresses: []string{"10.0.0.2", "fda0:23::2", "8.8.8.8", "2001:db8::2"}, | ||
info: &info.Info{ | ||
Network: []info.Network{ | ||
{ | ||
IPv4: []string{"10.0.0.2"}, | ||
IPv6: []string{"fda0:23::2"}, | ||
}, | ||
{ | ||
IPv4: []string{"8.8.8.8"}, | ||
IPv6: []string{"2001:db8::2"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{ | ||
"10.0.0.2": v1.NodeInternalIP, | ||
"fda0:23::2": v1.NodeInternalIP, | ||
"8.8.8.8": v1.NodeExternalIP, | ||
"2001:db8::2": v1.NodeExternalIP, | ||
}) | ||
}) | ||
|
||
t.Run("instance with both reservedAddresses and info set, some overlap, each adding some", func(t *testing.T) { | ||
instance := anexiaInstance{ | ||
reservedAddresses: []string{"10.0.0.2", "8.8.8.8", "2001:db8::2"}, | ||
info: &info.Info{ | ||
Network: []info.Network{ | ||
{ | ||
IPv4: []string{"10.0.0.2"}, | ||
IPv6: []string{"fda0:23::2"}, | ||
}, | ||
{ | ||
IPv6: []string{"2001:db8::2"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{ | ||
"10.0.0.2": v1.NodeInternalIP, | ||
"fda0:23::2": v1.NodeInternalIP, | ||
"8.8.8.8": v1.NodeExternalIP, | ||
"2001:db8::2": v1.NodeExternalIP, | ||
}) | ||
}) | ||
} |
Oops, something went wrong.