Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ipam
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/v1alpha1/ionoscloudmachine_types.go
#	api/v1alpha1/ionoscloudmachine_types_test.go
#	api/v1alpha1/zz_generated.deepcopy.go
#	config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudmachines.yaml
#	config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudmachinetemplates.yaml
#	internal/service/cloud/server.go
  • Loading branch information
Mattes83 committed Aug 27, 2024
2 parents 82098f9 + 0c67905 commit 9d08080
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 87 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ This provider's versions are compatible with the following versions of Cluster A
| | Cluster API v1beta1 (v1.7) |
|------------------------|:--------------------------:|
| CAPIC v1alpha1 (v0.2) ||
| CAPIC v1alpha1 (v0.3) ||
| CAPIC v1alpha1 (v0.4) ||

### Kubernetes Versions

Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/ionoscloudcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
IonosCloudClusterKind = "IonosCloudCluster"
)

//+kubebuilder:validation:XValidation:rule="self.controlPlaneEndpoint.host == '' || has(self.location)",message="location is required when controlPlaneEndpoint.host is set"

// IonosCloudClusterSpec defines the desired state of IonosCloudCluster.
type IonosCloudClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
Expand All @@ -44,10 +46,12 @@ type IonosCloudClusterSpec struct {
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty"`

// Location is the location where the data centers should be located.
//
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="location is immutable"
//+kubebuilder:example=de/txl
//+kubebuilder:validation:MinLength=1
Location string `json:"location"`
//+optional
Location string `json:"location,omitempty"`

// CredentialsRef is a reference to the secret containing the credentials to access the IONOS Cloud API.
//+kubebuilder:validation:XValidation:rule="has(self.name) && self.name != ''",message="credentialsRef.name must be provided"
Expand Down
10 changes: 8 additions & 2 deletions api/v1alpha1/ionoscloudcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ var _ = Describe("IonosCloudCluster", func() {
Expect(k8sClient.Create(context.Background(), cluster)).
Should(MatchError(ContainSubstring("credentialsRef.name must be provided")))
})
It("should not allow creating clusters with empty location", func() {
It("should not allow creating clusters with empty location when ControlPlaneEndpoint host is set", func() {
cluster := defaultCluster()
cluster.Spec.Location = ""
Expect(k8sClient.Create(context.Background(), cluster)).
Should(MatchError(ContainSubstring("spec.location in body should be at least 1 chars long")))
Should(MatchError(ContainSubstring("location is required when controlPlaneEndpoint.host is set")))
})
It("should allow creating clusters with empty location when ControlPlaneEndpoint host is not set", func() {
cluster := defaultCluster()
cluster.Spec.Location = ""
cluster.Spec.ControlPlaneEndpoint.Host = ""
Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed())
})
})

Expand Down
11 changes: 10 additions & 1 deletion api/v1alpha1/ionoscloudmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ type IonosCloudMachineSpec struct {
Disk *Volume `json:"disk"`

// AdditionalNetworks defines the additional network configurations for the VM.
// NOTE(lubedacht): We currently only support networks with DHCP enabled.
//+optional
AdditionalNetworks Networks `json:"additionalNetworks,omitempty"`

Expand Down Expand Up @@ -188,6 +187,16 @@ type Network struct {
//+kubebuilder:validation:Minimum=1
NetworkID int32 `json:"networkID"`

// VNET is solely used for internal purposes and requires elevated permissions.
//+optional
VNET *string `json:"vnet,omitempty"`

// DHCP indicates whether DHCP is enabled for the LAN.
// The primary NIC will always have DHCP enabled.
//+kubebuilder:default=true
//+optional
DHCP *bool `json:"dhcp,omitempty"`

// IPAMConfig allows to obtain IP Addresses from existing IP pools instead of using DHCP.
IPAMConfig `json:",inline"`
}
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/ionoscloudmachine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ var _ = Describe("IonosCloudMachine Tests", func() {
Entry("invalid IPv4PoolRef with invalid apiGroup", "IPv4", "InClusterIPPool", "SomeWrongAPIGroup", "ipv4-pool"),
Entry("invalid IPv4PoolRef with empty name", "IPv4", "InClusterIPPool", "ipam.cluster.x-k8s.io", ""),
)
It("DHCP should default to true", func() {
m := defaultMachine()
Expect(k8sClient.Create(context.Background(), m)).To(Succeed())
Expect(*m.Spec.AdditionalNetworks[0].DHCP).To(BeTrue())
})
})
})
Context("FailoverIP", func() {
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clusterctl-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "infrastructure-ionoscloud",
"config": {
"componentsFile": "infrastructure-components.yaml",
"nextVersion": "v0.2.0"
"nextVersion": "v0.4.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ spec:
rule: self == oldSelf
required:
- credentialsRef
- location
type: object
x-kubernetes-validations:
- message: location is required when controlPlaneEndpoint.host is set
rule: self.controlPlaneEndpoint.host == '' || has(self.location)
status:
description: IonosCloudClusterStatus defines the observed state of IonosCloudCluster.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ spec:
rule: self == oldSelf
required:
- credentialsRef
- location
type: object
x-kubernetes-validations:
- message: location is required when controlPlaneEndpoint.host
is set
rule: self.controlPlaneEndpoint.host == '' || has(self.location)
required:
- spec
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ spec:
description: IonosCloudMachineSpec defines the desired state of IonosCloudMachine.
properties:
additionalNetworks:
description: |-
AdditionalNetworks defines the additional network configurations for the VM.
NOTE(lubedacht): We currently only support networks with DHCP enabled.
description: AdditionalNetworks defines the additional network configurations
for the VM.
items:
description: Network contains the config for additional LANs.
properties:
Expand Down Expand Up @@ -128,13 +127,23 @@ spec:
rule: self.kind == 'InClusterIPPool' || self.kind == 'GlobalInClusterIPPool'
- message: ipv6PoolRef.name is required
rule: self.name != ''
dhcp:
default: true
description: |-
DHCP indicates whether DHCP is enabled for the LAN.
The primary NIC will always have DHCP enabled.
type: boolean
networkID:
description: |-
NetworkID represents an ID an existing LAN in the data center.
This LAN will be excluded from the deletion process.
format: int32
minimum: 1
type: integer
vnet:
description: VNET is solely used for internal purposes and requires
elevated permissions.
type: string
required:
- networkID
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ spec:
description: Spec is the IonosCloudMachineSpec for the IonosCloudMachineTemplate.
properties:
additionalNetworks:
description: |-
AdditionalNetworks defines the additional network configurations for the VM.
NOTE(lubedacht): We currently only support networks with DHCP enabled.
description: AdditionalNetworks defines the additional network
configurations for the VM.
items:
description: Network contains the config for additional
LANs.
Expand Down Expand Up @@ -148,13 +147,23 @@ spec:
== 'GlobalInClusterIPPool'
- message: ipv6PoolRef.name is required
rule: self.name != ''
dhcp:
default: true
description: |-
DHCP indicates whether DHCP is enabled for the LAN.
The primary NIC will always have DHCP enabled.
type: boolean
networkID:
description: |-
NetworkID represents an ID an existing LAN in the data center.
This LAN will be excluded from the deletion process.
format: int32
minimum: 1
type: integer
vnet:
description: VNET is solely used for internal purposes
and requires elevated permissions.
type: string
required:
- networkID
type: object
Expand Down
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/ionos-cloud/sdk-go/v6 v6.1.11
github.com/ionos-cloud/sdk-go/v6 v6.2.1
github.com/jarcoal/httpmock v1.3.1
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/onsi/ginkgo/v2 v2.19.1
github.com/onsi/gomega v1.34.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
k8s.io/api v0.29.7
Expand Down Expand Up @@ -41,7 +41,7 @@ require (
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/docker v25.0.6+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
Expand Down Expand Up @@ -116,22 +116,21 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/tools v0.23.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 9d08080

Please sign in to comment.