Skip to content

Commit f620d39

Browse files
Increment API version to support new reconciliation API and move rel… (#232)
* Increment API version to support new reconciliation API and move related fields
1 parent ee5de6b commit f620d39

File tree

140 files changed

+22488
-2206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+22488
-2206
lines changed

Makefile

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ GINKGO := $(BIN_DIR)/$(GINKGO_BIN)
7979
CONTROLLER_GEN_BIN = controller-gen
8080
CONTROLLER_GEN := $(BIN_DIR)/$(CONTROLLER_GEN_BIN)
8181

82+
CONVERSION_GEN_BIN := conversion-gen
83+
CONVERSION_GEN := $(BIN_DIR)/conversion-gen
84+
85+
# set up `setup-envtest` to install kubebuilder dependency
86+
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.24.2
87+
SETUP_ENVTEST_VER := v0.0.0-20230131074648-f5014c077fc3
88+
SETUP_ENVTEST_BIN := setup-envtest
89+
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
90+
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
91+
8292
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8393
ifeq (,$(shell go env GOBIN))
8494
GOBIN=$(shell go env GOPATH)/bin
@@ -92,6 +102,11 @@ endif
92102
SHELL = /usr/bin/env bash -o pipefail
93103
.SHELLFLAGS = -ec
94104

105+
# set --output-base used for conversion-gen which needs to be different for in GOPATH and outside GOPATH dev
106+
ifneq ($(abspath $(ROOT_DIR)),$(GOPATH)/src/github.com/oracle/cluster-api-provider-oci)
107+
OUTPUT_BASE := --output-base=$(ROOT_DIR)
108+
endif
109+
95110
all: build
96111

97112
##@ General
@@ -119,28 +134,49 @@ manifests: $(CONTROLLER_GEN) ## Generate WebhookConfiguration, ClusterRole and C
119134
paths="./exp/api/..." \
120135
output:crd:artifacts:config=config/crd/bases
121136

122-
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
137+
generate: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
123138
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..." paths="./exp/api/..."
139+
$(CONVERSION_GEN) \
140+
--input-dirs=./api/v1beta1 \
141+
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
142+
--build-tag=ignore_autogenerated_conversions \
143+
--output-file-base=zz_generated.conversion \
144+
--go-header-file=hack/boilerplate.go.txt $(OUTPUT_BASE)
145+
$(CONVERSION_GEN) \
146+
--input-dirs=./exp/api/v1beta1 \
147+
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
148+
--extra-peer-dirs=github.com/oracle/cluster-api-provider-oci/api/v1beta1 \
149+
--build-tag=ignore_autogenerated_conversions \
150+
--output-file-base=zz_generated.conversion \
151+
--go-header-file=hack/boilerplate.go.txt $(OUTPUT_BASE)
124152

125153
fmt: ## Run go fmt against code.
126154
go fmt ./...
127155

128-
vet: ## Run go vet against code.
129-
go vet ./...
156+
##@ test:
157+
158+
.PHONY: install-setup-envtest
159+
install-setup-envtest: # Install setup-envtest so that setup-envtest's eval is executed after the tool has been installed.
160+
GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
130161

131-
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
132-
test: manifests generate fmt vet ## Run tests.
133-
mkdir -p ${ENVTEST_ASSETS_DIR}
134-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
135-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
162+
.PHONY: setup-envtest
163+
setup-envtest: install-setup-envtest # Build setup-envtest from tools folder.
164+
@$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
165+
if [ -z "$(KUBEBUILDER_ASSETS)" ]; then echo "Failed to find kubebuilder assets, see errors above"; exit 1; fi; \
166+
echo "kube-builder assets: $(KUBEBUILDER_ASSETS)"
136167

168+
.PHONY: test
169+
test: setup-envtest ## Run tests
170+
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -coverprofile=coverage.out ./... $(TEST_ARGS)
171+
go tool cover -func=coverage.out -o coverage.txt
172+
go tool cover -html=coverage.out -o coverage.html
137173

138174
##@ Build
139175

140-
build: generate fmt vet ## Build manager binary.
176+
build: generate fmt ## Build manager binary.
141177
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS} -extldflags '-static'" -o bin/manager .
142178

143-
run: manifests generate fmt vet ## Run a controller from your host.
179+
run: manifests generate fmt ## Run a controller from your host.
144180
go run ./main.go --feature-gates=MachinePool=${EXP_MACHINE_POOL}
145181

146182
## --------------------------------------
@@ -332,6 +368,9 @@ kubectl: $(KUBECTL) ## Build a local copy of kubectl.
332368
$(CONTROLLER_GEN): ## Download controller-gen locally if necessary.
333369
GOBIN=$(BIN_DIR)/ $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) v0.10.0
334370

371+
$(CONVERSION_GEN): ## Download controller-gen locally if necessary.
372+
GOBIN=$(BIN_DIR)/ $(GO_INSTALL) k8s.io/code-generator/cmd/conversion-gen $(CONVERSION_GEN_BIN) v0.23.1
373+
335374
$(KUSTOMIZE): ## Download kustomize locally if necessary.
336375
GOBIN=$(BIN_DIR)/ $(GO_INSTALL) sigs.k8s.io/kustomize/kustomize/v4 $(KUSTOMIZE_BIN) v4.5.2
337376

api/v1beta1/conversion.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
Copyright (c) 2023 Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"errors"
21+
"github.com/oracle/cluster-api-provider-oci/api/v1beta2"
22+
"k8s.io/apimachinery/pkg/conversion"
23+
)
24+
25+
// Convert_v1beta1_VCN_To_v1beta2_VCN converts v1beta1 VCN to v1beta2 VCN
26+
func Convert_v1beta1_VCN_To_v1beta2_VCN(in *VCN, out *v1beta2.VCN, s conversion.Scope) error {
27+
autoConvert_v1beta1_VCN_To_v1beta2_VCN(in, out, s)
28+
if in.InternetGatewayId != nil {
29+
out.InternetGateway.Id = in.InternetGatewayId
30+
}
31+
if in.NatGatewayId != nil {
32+
out.NATGateway.Id = in.NatGatewayId
33+
}
34+
if in.ServiceGatewayId != nil {
35+
out.ServiceGateway.Id = in.ServiceGatewayId
36+
}
37+
if in.PrivateRouteTableId != nil {
38+
out.RouteTable.PrivateRouteTableId = in.PrivateRouteTableId
39+
}
40+
if in.PublicRouteTableId != nil {
41+
out.RouteTable.PublicRouteTableId = in.PublicRouteTableId
42+
}
43+
if in.NetworkSecurityGroups != nil {
44+
nsgList, err := convertv1beta1NSGListTov1beta2NSGList(in.NetworkSecurityGroups)
45+
if err != nil {
46+
return err
47+
}
48+
out.NetworkSecurityGroup.List = nsgList
49+
}
50+
return nil
51+
}
52+
53+
// Convert_v1beta2_VCN_To_v1beta1_VCN converts v1beta2 VCN to v1beta1 VCN
54+
func Convert_v1beta2_VCN_To_v1beta1_VCN(in *v1beta2.VCN, out *VCN, s conversion.Scope) error {
55+
autoConvert_v1beta2_VCN_To_v1beta1_VCN(in, out, s)
56+
if in.InternetGateway.Id != nil {
57+
out.InternetGatewayId = in.InternetGateway.Id
58+
}
59+
if in.NATGateway.Id != nil {
60+
out.NatGatewayId = in.NATGateway.Id
61+
}
62+
if in.ServiceGateway.Id != nil {
63+
out.ServiceGatewayId = in.ServiceGateway.Id
64+
}
65+
if in.RouteTable.PublicRouteTableId != nil {
66+
out.PublicRouteTableId = in.RouteTable.PublicRouteTableId
67+
}
68+
if in.RouteTable.PrivateRouteTableId != nil {
69+
out.PrivateRouteTableId = in.RouteTable.PrivateRouteTableId
70+
}
71+
if in.NetworkSecurityGroup.List != nil {
72+
nsgList, err := convertv1beta2NSGListTov1beta1NSGList(in.NetworkSecurityGroup.List)
73+
if err != nil {
74+
return err
75+
}
76+
out.NetworkSecurityGroups = nsgList
77+
}
78+
return nil
79+
}
80+
81+
// Convert_v1beta1_OCIClusterStatus_To_v1beta2_OCIClusterStatus converts v1beta1 OCIClusterStatus to v1beta2 OCIClusterStatus
82+
func Convert_v1beta1_OCIClusterStatus_To_v1beta2_OCIClusterStatus(in *OCIClusterStatus, out *v1beta2.OCIClusterStatus, s conversion.Scope) error {
83+
return autoConvert_v1beta1_OCIClusterStatus_To_v1beta2_OCIClusterStatus(in, out, s)
84+
}
85+
86+
// Convert_v1beta2_OCIClusterSpec_To_v1beta1_OCIClusterSpec converts v1beta2 OCIClusterStatus to v1beta1 OCIClusterStatus
87+
func Convert_v1beta2_OCIClusterSpec_To_v1beta1_OCIClusterSpec(in *v1beta2.OCIClusterSpec, out *OCIClusterSpec, s conversion.Scope) error {
88+
return autoConvert_v1beta2_OCIClusterSpec_To_v1beta1_OCIClusterSpec(in, out, s)
89+
}
90+
91+
// Convert_v1beta1_EgressSecurityRuleForNSG_To_v1beta2_EgressSecurityRuleForNSG converts v1beta1 EgressSecurityRuleForNSG to v1beta2 EgressSecurityRuleForNSG
92+
func Convert_v1beta1_EgressSecurityRuleForNSG_To_v1beta2_EgressSecurityRuleForNSG(in *EgressSecurityRuleForNSG, out *v1beta2.EgressSecurityRuleForNSG, s conversion.Scope) error {
93+
return autoConvert_v1beta1_EgressSecurityRuleForNSG_To_v1beta2_EgressSecurityRuleForNSG(in, out, s)
94+
}
95+
96+
// Convert_v1beta1_IngressSecurityRuleForNSG_To_v1beta2_IngressSecurityRuleForNSG converts v1beta1 IngressSecurityRuleForNSG to v1beta2 IngressSecurityRuleForNSG
97+
func Convert_v1beta1_IngressSecurityRuleForNSG_To_v1beta2_IngressSecurityRuleForNSG(in *IngressSecurityRuleForNSG, out *v1beta2.IngressSecurityRuleForNSG, s conversion.Scope) error {
98+
return autoConvert_v1beta1_IngressSecurityRuleForNSG_To_v1beta2_IngressSecurityRuleForNSG(in, out, s)
99+
}
100+
101+
// Convert_v1beta1_NetworkDetails_To_v1beta2_NetworkDetails converts v1beta1 NetworkDetails to v1beta2 NetworkDetails
102+
func Convert_v1beta1_NetworkDetails_To_v1beta2_NetworkDetails(in *NetworkDetails, out *v1beta2.NetworkDetails, s conversion.Scope) error {
103+
return autoConvert_v1beta1_NetworkDetails_To_v1beta2_NetworkDetails(in, out, s)
104+
}
105+
106+
// Convert_v1beta1_OCIMachineSpec_To_v1beta2_OCIMachineSpec converts v1beta1 OCIMachineSpec to v1beta2 OCIMachineSpec
107+
func Convert_v1beta1_OCIMachineSpec_To_v1beta2_OCIMachineSpec(in *OCIMachineSpec, out *v1beta2.OCIMachineSpec, s conversion.Scope) error {
108+
err := autoConvert_v1beta1_OCIMachineSpec_To_v1beta2_OCIMachineSpec(in, out, s)
109+
if err != nil {
110+
return err
111+
}
112+
if in.NetworkDetails.SubnetId != nil {
113+
return errors.New("deprecated field NetworkDetails.SubnetId is present in OCIMachineSpec")
114+
}
115+
if in.NetworkDetails.NSGId != nil {
116+
return errors.New("deprecated field NetworkDetails.NSGId is present in OCIMachineSpec")
117+
}
118+
if in.NSGName != "" && len(in.NetworkDetails.NsgNames) == 0 {
119+
out.NetworkDetails.NsgNames = []string{in.NSGName}
120+
}
121+
return nil
122+
}

api/v1beta1/conversion_test.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
Copyright (c) 2023 Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
21+
"testing"
22+
23+
fuzz "github.com/google/gofuzz"
24+
. "github.com/onsi/gomega"
25+
"github.com/oracle/cluster-api-provider-oci/api/v1beta2"
26+
"k8s.io/apimachinery/pkg/runtime"
27+
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
29+
)
30+
31+
func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
32+
return []interface{}{
33+
OCIMachineFuzzer,
34+
OCIMachineTemplateFuzzer,
35+
OCIClusterFuzzer,
36+
OCIClusterTemplateFuzzer,
37+
}
38+
}
39+
40+
func OCIMachineFuzzer(obj *OCIMachine, c fuzz.Continue) {
41+
c.FuzzNoCustom(obj)
42+
// nil fields which have been removed so that tests dont fail
43+
obj.Spec.NetworkDetails.NSGId = nil
44+
obj.Spec.NetworkDetails.SubnetId = nil
45+
obj.Spec.NSGName = ""
46+
}
47+
48+
func OCIClusterFuzzer(obj *OCICluster, c fuzz.Continue) {
49+
c.FuzzNoCustom(obj)
50+
// nil fields which have been removed so that tests dont fail
51+
for _, nsg := range obj.Spec.NetworkSpec.Vcn.NetworkSecurityGroups {
52+
if nsg != nil {
53+
ingressRules := make([]IngressSecurityRuleForNSG, len(nsg.IngressRules))
54+
for _, rule := range nsg.IngressRules {
55+
rule.ID = nil
56+
ingressRules = append(ingressRules, rule)
57+
}
58+
nsg.IngressRules = ingressRules
59+
60+
egressRules := make([]EgressSecurityRuleForNSG, len(nsg.EgressRules))
61+
for _, rule := range nsg.EgressRules {
62+
(&rule).ID = nil
63+
egressRules = append(egressRules, rule)
64+
}
65+
nsg.EgressRules = egressRules
66+
}
67+
}
68+
}
69+
70+
func OCIClusterTemplateFuzzer(obj *OCIClusterTemplate, c fuzz.Continue) {
71+
c.FuzzNoCustom(obj)
72+
// nil fields which have been removed so that tests dont fail
73+
for _, nsg := range obj.Spec.Template.Spec.NetworkSpec.Vcn.NetworkSecurityGroups {
74+
if nsg != nil {
75+
ingressRules := make([]IngressSecurityRuleForNSG, len(nsg.IngressRules))
76+
for _, rule := range nsg.IngressRules {
77+
rule.ID = nil
78+
ingressRules = append(ingressRules, rule)
79+
}
80+
nsg.IngressRules = ingressRules
81+
82+
egressRules := make([]EgressSecurityRuleForNSG, len(nsg.EgressRules))
83+
for _, rule := range nsg.EgressRules {
84+
(&rule).ID = nil
85+
egressRules = append(egressRules, rule)
86+
}
87+
nsg.EgressRules = egressRules
88+
}
89+
}
90+
}
91+
92+
func OCIMachineTemplateFuzzer(obj *OCIMachineTemplate, c fuzz.Continue) {
93+
c.FuzzNoCustom(obj)
94+
// nil fields which ave been removed so that tests dont fail
95+
obj.Spec.Template.Spec.NetworkDetails.NSGId = nil
96+
obj.Spec.Template.Spec.NetworkDetails.SubnetId = nil
97+
obj.Spec.Template.Spec.NSGName = ""
98+
}
99+
100+
func TestFuzzyConversion(t *testing.T) {
101+
g := NewWithT(t)
102+
scheme := runtime.NewScheme()
103+
g.Expect(AddToScheme(scheme)).To(Succeed())
104+
g.Expect(v1beta2.AddToScheme(scheme)).To(Succeed())
105+
106+
t.Run("for OCICluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
107+
Scheme: scheme,
108+
Hub: &v1beta2.OCICluster{},
109+
Spoke: &OCICluster{},
110+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
111+
}))
112+
113+
t.Run("for OCIClusterTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
114+
Scheme: scheme,
115+
Hub: &v1beta2.OCIClusterTemplate{},
116+
Spoke: &OCIClusterTemplate{},
117+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
118+
}))
119+
120+
t.Run("for OCIMachine", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
121+
Scheme: scheme,
122+
Hub: &v1beta2.OCIMachine{},
123+
Spoke: &OCIMachine{},
124+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
125+
}))
126+
127+
t.Run("for OCIMachineTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
128+
Scheme: scheme,
129+
Hub: &v1beta2.OCIMachineTemplate{},
130+
Spoke: &OCIMachineTemplate{},
131+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
132+
}))
133+
134+
t.Run("for OCIClusterIdentity", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
135+
Scheme: scheme,
136+
Hub: &v1beta2.OCIClusterIdentity{},
137+
Spoke: &OCIClusterIdentity{},
138+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
139+
}))
140+
141+
}

api/v1beta1/doc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright (c) 2023 Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:conversion-gen=github.com/oracle/cluster-api-provider-oci/api/v1beta2
18+
19+
package v1beta1

api/v1beta1/groupversion_info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ var (
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.
3535
AddToScheme = SchemeBuilder.AddToScheme
36+
37+
localSchemeBuilder = SchemeBuilder.SchemeBuilder
3638
)

0 commit comments

Comments
 (0)