Skip to content

Commit

Permalink
feat: Allow firewall rules to be defined for the API server load bala…
Browse files Browse the repository at this point in the history
…ncer

also allows load balancing additional ports to the API server
  • Loading branch information
hrak committed Aug 12, 2024
1 parent 526fff9 commit b40f377
Show file tree
Hide file tree
Showing 23 changed files with 1,031 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ issues:
- path: _test\.go
linters:
- gosec
- text: "SA1019: .+LBRuleID is deprecated"
linters:
- staticcheck
17 changes: 17 additions & 0 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -53,3 +54,19 @@ func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in, out, s)
}

func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *v1beta3.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.APIServerLoadBalancer = &infrav1.LoadBalancer{}
out.LoadBalancerRuleIDs = []string{in.LBRuleID}
out.Ready = in.Ready
return nil
}

func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.Ready = in.Ready
return nil
}
8 changes: 5 additions & 3 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ limitations under the License.
package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nolint
Expand All @@ -43,6 +42,9 @@ func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { /
if restored.Spec.Template.Spec.UncompressedUserData != nil {
dst.Spec.Template.Spec.UncompressedUserData = restored.Spec.Template.Spec.UncompressedUserData
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta

return nil
}

Expand Down
5 changes: 2 additions & 3 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package v1beta1

import (
"context"
"fmt"

"errors"
corev1 "k8s.io/api/core/v1"
machineryconversion "k8s.io/apimachinery/pkg/conversion"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -51,7 +50,7 @@ func Convert_v1beta1_CloudStackCluster_To_v1beta3_CloudStackCluster(in *CloudSta
//nolint:golint,revive,stylecheck
func Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(in *infrav1.CloudStackCluster, out *CloudStackCluster, _ machineryconversion.Scope) error {
if len(in.Spec.FailureDomains) < 1 {
return fmt.Errorf("infrav1 to v1beta1 conversion not supported when < 1 failure domain is provided. Input CloudStackCluster spec %s", in.Spec)
return errors.New("infrav1 to v1beta1 conversion not supported when < 1 failure domain is provided")
}
out.ObjectMeta = in.ObjectMeta
out.Spec = CloudStackClusterSpec{
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -103,6 +104,11 @@ var _ = Describe("Conversion", func() {
Host: "endpoint1",
Port: 443,
},
APIServerLoadBalancer: &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
AdditionalPorts: []int{},
AllowedCIDRs: []string{},
},
},
Status: v1beta3.CloudStackClusterStatus{},
}
Expand Down
29 changes: 29 additions & 0 deletions api/v1beta1/v1beta1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Kubernetes 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 v1beta1_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestV1beta1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "V1beta1 Suite")
}
33 changes: 13 additions & 20 deletions api/v1beta1/zz_generated.conversion.go

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

24 changes: 24 additions & 0 deletions api/v1beta2/cloudstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta2

import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand All @@ -30,3 +32,25 @@ func (dst *CloudStackCluster) ConvertFrom(srcRaw conversion.Hub) error { // noli
src := srcRaw.(*v1beta3.CloudStackCluster)
return Convert_v1beta3_CloudStackCluster_To_v1beta2_CloudStackCluster(src, dst, nil)
}

func Convert_v1beta3_CloudStackClusterSpec_To_v1beta2_CloudStackClusterSpec(in *v1beta3.CloudStackClusterSpec, out *CloudStackClusterSpec, s machineryconversion.Scope) error { // nolint
err := autoConvert_v1beta3_CloudStackClusterSpec_To_v1beta2_CloudStackClusterSpec(in, out, s)
if err != nil {
return err
}

return nil
}

func Convert_v1beta2_CloudStackClusterSpec_To_v1beta3_CloudStackClusterSpec(in *CloudStackClusterSpec, out *v1beta3.CloudStackClusterSpec, s machineryconversion.Scope) error { // nolint
err := autoConvert_v1beta2_CloudStackClusterSpec_To_v1beta3_CloudStackClusterSpec(in, out, s)
if err != nil {
return err
}

out.APIServerLoadBalancer = &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
}

return nil
}
16 changes: 16 additions & 0 deletions api/v1beta2/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta2

import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand All @@ -30,3 +31,18 @@ func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta3.CloudStackIsolatedNetwork)
return Convert_v1beta3_CloudStackIsolatedNetwork_To_v1beta2_CloudStackIsolatedNetwork(src, dst, nil)
}

func Convert_v1beta2_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *v1beta3.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.LoadBalancerRuleIDs = []string{in.LBRuleID}
out.Ready = in.Ready
return nil
}

func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta2_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.Ready = in.Ready
return nil
}
3 changes: 3 additions & 0 deletions api/v1beta2/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { /
if restored.Spec.Template.Spec.UncompressedUserData != nil {
dst.Spec.Template.Spec.UncompressedUserData = restored.Spec.Template.Spec.UncompressedUserData
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta

return nil
}

Expand Down
Loading

0 comments on commit b40f377

Please sign in to comment.