Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream merge #231

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ E2E_DATA_DIR ?= $(REPO_ROOT)/test/e2e/data
E2E_CONF_PATH ?= $(E2E_DATA_DIR)/e2e_conf.yaml
KUBETEST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance.yaml)
KUBETEST_FAST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance-fast.yaml)
GO_INSTALL := ./scripts/go_install.sh

# Binaries.
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
Expand All @@ -53,6 +54,17 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes

# Setup-envtest
SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9
SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest

# Kubebuilder
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.23.3
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?= 60s

PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
export PATH
export DOCKER_CLI_EXPERIMENTAL=enabled
Expand Down Expand Up @@ -116,9 +128,15 @@ E2E_ARGS ?=
$(ARTIFACTS):
mkdir -p $@

ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
else
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
endif

.PHONY: test
test: ## Run tests
go test -v ./...
test: $(SETUP_ENVTEST) ## Run tests
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v ./... $(TEST_ARGS)

# Can be run manually, e.g. via:
# export OPENSTACK_CLOUD_YAML_FILE="$(pwd)/clouds.yaml"
Expand Down Expand Up @@ -167,6 +185,12 @@ managers:
manager-openstack-infrastructure: ## Build manager binary.
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS} -extldflags '-static'" -o $(BIN_DIR)/manager .

$(SETUP_ENVTEST): # Build setup-envtest from tools folder.
GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)

.PHONY: $(SETUP_ENVTEST_BIN)
$(SETUP_ENVTEST_BIN): $(SETUP_ENVTEST) ## Build a local copy of setup-envtest.

## --------------------------------------
## Linting
## --------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha3

import (
unsafe "unsafe"

corev1 "k8s.io/api/core/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
Expand Down Expand Up @@ -117,6 +119,10 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
Name: in.CloudsSecret.Name,
}
}
out.APIServerLoadBalancer = infrav1.APIServerLoadBalancer{
Enabled: in.ManagedAPIServerLoadBalancer,
AdditionalPorts: *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)),
}
return autoConvert_v1alpha3_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s)
}

Expand All @@ -139,6 +145,10 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in *i
Name: in.Bastion.Instance.IdentityRef.Name,
}
}

out.ManagedAPIServerLoadBalancer = in.APIServerLoadBalancer.Enabled
out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancer.AdditionalPorts))

return autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in, out, s)
}

Expand Down
83 changes: 83 additions & 0 deletions api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,93 @@ import (
runtime "k8s.io/apimachinery/pkg/runtime"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)

func TestConvertTo(t *testing.T) {
g := gomega.NewWithT(t)
scheme := runtime.NewScheme()
g.Expect(AddToScheme(scheme)).To(gomega.Succeed())
g.Expect(infrav1.AddToScheme(scheme)).To(gomega.Succeed())

tests := []struct {
name string
spoke ctrlconversion.Convertible
hub ctrlconversion.Hub
want ctrlconversion.Hub
}{
{
name: "APIServer LoadBalancer Configuration",
spoke: &OpenStackCluster{
Spec: OpenStackClusterSpec{
ManagedAPIServerLoadBalancer: true,
APIServerLoadBalancerAdditionalPorts: []int{80, 443},
},
},
hub: &infrav1.OpenStackCluster{},
want: &infrav1.OpenStackCluster{
Spec: infrav1.OpenStackClusterSpec{
APIServerLoadBalancer: infrav1.APIServerLoadBalancer{
Enabled: true,
AdditionalPorts: []int{80, 443},
},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.spoke.ConvertTo(tt.hub)
g.Expect(err).NotTo(gomega.HaveOccurred())
g.Expect(tt.hub).To(gomega.Equal(tt.want))
})
}
}

func TestConvertFrom(t *testing.T) {
g := gomega.NewWithT(t)
scheme := runtime.NewScheme()
g.Expect(AddToScheme(scheme)).To(gomega.Succeed())
g.Expect(infrav1.AddToScheme(scheme)).To(gomega.Succeed())

tests := []struct {
name string
spoke ctrlconversion.Convertible
hub ctrlconversion.Hub
want ctrlconversion.Convertible
}{
{
name: "APIServer LoadBalancer Configuration",
spoke: &OpenStackCluster{},
hub: &infrav1.OpenStackCluster{
Spec: infrav1.OpenStackClusterSpec{
APIServerLoadBalancer: infrav1.APIServerLoadBalancer{
Enabled: true,
AdditionalPorts: []int{80, 443},
},
},
},
want: &OpenStackCluster{
Spec: OpenStackClusterSpec{
ManagedAPIServerLoadBalancer: true,
APIServerLoadBalancerAdditionalPorts: []int{80, 443},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.spoke.ConvertFrom(tt.hub)
g.Expect(err).NotTo(gomega.HaveOccurred())
g.Expect(tt.spoke).To(gomega.Equal(tt.want))
})
}
}

func TestFuzzyConversion(t *testing.T) {
g := gomega.NewWithT(t)
scheme := runtime.NewScheme()
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha3/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ type OpenStackClusterSpec struct {
ControlPlaneAvailabilityZones []string `json:"controlPlaneAvailabilityZones,omitempty"`

// Bastion is the OpenStack instance to login the nodes
//
// As a rolling update is not ideal during a bastion host session, we
// prevent changes to a running bastion configuration. Set `enabled: false` to
// make changes.
//+optional
Bastion *Bastion `json:"bastion,omitempty"`
}
Expand Down
7 changes: 3 additions & 4 deletions api/v1alpha3/zz_generated.conversion.go

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

36 changes: 36 additions & 0 deletions api/v1alpha4/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ func TestConvertTo(t *testing.T) {
},
},
},
{
name: "APIServer LoadBalancer Configuration",
spoke: &OpenStackCluster{
Spec: OpenStackClusterSpec{
ManagedAPIServerLoadBalancer: true,
APIServerLoadBalancerAdditionalPorts: []int{80, 443},
},
},
hub: &infrav1.OpenStackCluster{},
want: &infrav1.OpenStackCluster{
Spec: infrav1.OpenStackClusterSpec{
APIServerLoadBalancer: infrav1.APIServerLoadBalancer{
Enabled: true,
AdditionalPorts: []int{80, 443},
},
},
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -121,6 +139,24 @@ func TestConvertFrom(t *testing.T) {
},
},
},
{
name: "APIServer LoadBalancer Configuration",
spoke: &OpenStackCluster{},
hub: &infrav1.OpenStackCluster{
Spec: infrav1.OpenStackClusterSpec{
APIServerLoadBalancer: infrav1.APIServerLoadBalancer{
Enabled: true,
AdditionalPorts: []int{80, 443},
},
},
},
want: &OpenStackCluster{
Spec: OpenStackClusterSpec{
ManagedAPIServerLoadBalancer: true,
APIServerLoadBalancerAdditionalPorts: []int{80, 443},
},
},
},
}

for _, tt := range tests {
Expand Down
18 changes: 18 additions & 0 deletions api/v1alpha4/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ limitations under the License.
package v1alpha4

import (
unsafe "unsafe"

"k8s.io/apimachinery/pkg/conversion"
clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)

// Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint is an autogenerated conversion function.
Expand All @@ -31,3 +35,17 @@ func Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in *clusterv1alpha4.API
func Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in *clusterv1.APIEndpoint, out *clusterv1alpha4.APIEndpoint, s conversion.Scope) error {
return clusterv1alpha4.Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in, out, s)
}

func Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s conversion.Scope) error {
out.APIServerLoadBalancer.Enabled = in.ManagedAPIServerLoadBalancer
out.APIServerLoadBalancer.AdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts))

return autoConvert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s)
}

func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *infrav1.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error {
out.ManagedAPIServerLoadBalancer = in.APIServerLoadBalancer.Enabled
out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancer.AdditionalPorts))

return autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in, out, s)
}
4 changes: 4 additions & 0 deletions api/v1alpha4/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ type OpenStackClusterSpec struct {
ControlPlaneAvailabilityZones []string `json:"controlPlaneAvailabilityZones,omitempty"`

// Bastion is the OpenStack instance to login the nodes
//
// As a rolling update is not ideal during a bastion host session, we
// prevent changes to a running bastion configuration. Set `enabled: false` to
// make changes.
//+optional
Bastion *Bastion `json:"bastion,omitempty"`

Expand Down
Loading