Skip to content

Commit 0c34b97

Browse files
committed
Move ./exp/api => ./api/core
1 parent 28a446c commit 0c34b97

File tree

122 files changed

+3124
-3472
lines changed

Some content is hidden

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

122 files changed

+3124
-3472
lines changed

.golangci.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ linters:
132132
alias: clusterv1beta1
133133
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta2
134134
alias: clusterv1
135-
# CAPI exp
136-
- pkg: sigs.k8s.io/cluster-api/internal/apis/core/exp/v1alpha3
137-
alias: expv1alpha3
138-
- pkg: sigs.k8s.io/cluster-api/internal/apis/core/exp/v1alpha4
139-
alias: expv1alpha4
140-
- pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1
141-
alias: expv1beta1
142-
- pkg: sigs.k8s.io/cluster-api/exp/api/v1beta2
143-
alias: expv1
144135
# CAPI exp addons
145136
- pkg: sigs.k8s.io/cluster-api/internal/apis/addons/v1alpha3
146137
alias: addonsv1alpha3

Makefile

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ TRACE ?= 0
5959
#
6060
# Full directory of where the Makefile resides
6161
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
62-
EXP_DIR := exp
6362
BIN_DIR := bin
6463
TEST_DIR := test
6564
TOOLS_DIR := hack/tools
@@ -290,11 +289,10 @@ generate-manifests-core: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.
290289
paths=./internal/controllers/... \
291290
paths=./internal/webhooks/... \
292291
paths=./internal/apis/addons/... \
293-
paths=./$(EXP_DIR)/api/... \
294-
paths=./$(EXP_DIR)/internal/controllers/... \
295-
paths=./$(EXP_DIR)/internal/webhooks/... \
296-
paths=./$(EXP_DIR)/ipam/internal/webhooks/... \
297-
paths=./$(EXP_DIR)/runtime/internal/controllers/... \
292+
paths=./exp/internal/controllers/... \
293+
paths=./exp/internal/webhooks/... \
294+
paths=./exp/ipam/internal/webhooks/... \
295+
paths=./exp/runtime/internal/controllers/... \
298296
crd:crdVersions=v1 \
299297
rbac:roleName=manager-role \
300298
output:crd:dir=./config/crd/bases \
@@ -368,9 +366,9 @@ generate-manifests-docker-infrastructure: $(CONTROLLER_GEN) ## Generate manifest
368366
cd $(CAPD_DIR); $(CONTROLLER_GEN) \
369367
paths=./ \
370368
paths=./api/... \
371-
paths=./$(EXP_DIR)/api/... \
372-
paths=./$(EXP_DIR)/internal/controllers/... \
373-
paths=./$(EXP_DIR)/internal/webhooks/... \
369+
paths=./exp/api/... \
370+
paths=./exp/internal/controllers/... \
371+
paths=./exp/internal/webhooks/... \
374372
paths=./internal/controllers/... \
375373
paths=./internal/webhooks/... \
376374
crd:crdVersions=v1 \
@@ -392,7 +390,7 @@ generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets
392390

393391
.PHONY: generate-go-deepcopy-core
394392
generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for core
395-
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api/addons,./api/core,./api/ipam,./api/runtime,./internal/apis/addons,./internal/apis/core,./$(EXP_DIR)/api,./$(EXP_DIR)/runtime/hooks/api"
393+
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api/addons,./api/core,./api/ipam,./api/runtime,./internal/apis/addons,./internal/apis/core,./exp/runtime/hooks/api"
396394
$(CONTROLLER_GEN) \
397395
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
398396
paths=./api/addons/... \
@@ -401,8 +399,7 @@ generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for co
401399
paths=./api/runtime/... \
402400
paths=./internal/apis/addons/... \
403401
paths=./internal/apis/core/... \
404-
paths=./$(EXP_DIR)/api/... \
405-
paths=./$(EXP_DIR)/runtime/hooks/api/... \
402+
paths=./exp/runtime/hooks/api/... \
406403
paths=./internal/runtime/test/... \
407404
paths=./cmd/clusterctl/... \
408405
paths=./util/test/builder/... \
@@ -426,11 +423,11 @@ generate-go-deepcopy-kubeadm-control-plane: $(CONTROLLER_GEN) ## Generate deepco
426423

427424
.PHONY: generate-go-deepcopy-docker-infrastructure
428425
generate-go-deepcopy-docker-infrastructure: $(CONTROLLER_GEN) generate-go-deepcopy-in-memory-infrastructure ## Generate deepcopy go code for docker infrastructure provider
429-
$(MAKE) clean-generated-deepcopy SRC_DIRS="$(CAPD_DIR)/api,$(CAPD_DIR)/$(EXP_DIR)/api"
426+
$(MAKE) clean-generated-deepcopy SRC_DIRS="$(CAPD_DIR)/api,$(CAPD_DIR)/exp/api"
430427
cd $(CAPD_DIR); $(CONTROLLER_GEN) \
431428
object:headerFile=../../../hack/boilerplate/boilerplate.generatego.txt \
432429
paths=./api/... \
433-
paths=./$(EXP_DIR)/api/...
430+
paths=./exp/api/...
434431

435432
.PHONY: generate-go-deepcopy-in-memory-infrastructure
436433
generate-go-deepcopy-in-memory-infrastructure: $(CONTROLLER_GEN) ## Generate deepcopy go code for in-memory cloud resources
@@ -450,7 +447,6 @@ generate-go-conversions: ## Run all generate-go-conversions-* targets
450447
generate-go-conversions-core: ## Run all generate-go-conversions-core-* targets
451448
$(MAKE) generate-go-conversions-core-api
452449
$(MAKE) generate-go-conversions-addons-api
453-
$(MAKE) generate-go-conversions-core-exp
454450
$(MAKE) generate-go-conversions-core-ipam
455451
$(MAKE) generate-go-conversions-core-runtime
456452

@@ -474,16 +470,6 @@ generate-go-conversions-addons-api: $(CONVERSION_GEN) ## Generate conversions go
474470
./internal/apis/addons/v1alpha4 \
475471
./api/addons/v1beta1
476472

477-
.PHONY: generate-go-conversions-core-exp
478-
generate-go-conversions-core-exp: $(CONVERSION_GEN) ## Generate conversions go code for core exp
479-
$(MAKE) clean-generated-conversions SRC_DIRS="./exp/api/v1beta1,./internal/apis/core/exp/v1alpha3,./internal/apis/core/exp/v1alpha4"
480-
$(CONVERSION_GEN) \
481-
--output-file=zz_generated.conversion.go \
482-
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
483-
./internal/apis/core/exp/v1alpha3 \
484-
./internal/apis/core/exp/v1alpha4 \
485-
./$(EXP_DIR)/api/v1beta1
486-
487473
.PHONY: generate-go-conversions-core-ipam
488474
generate-go-conversions-core-ipam: $(CONVERSION_GEN) ## Generate conversions go code for core exp IPAM
489475
$(MAKE) clean-generated-conversions SRC_DIRS="./api/ipam/v1beta1,./api/ipam/v1alpha1"
@@ -542,8 +528,8 @@ generate-go-conversions-docker-infrastructure: $(CONVERSION_GEN) ## Generate con
542528
--go-header-file=../../../hack/boilerplate/boilerplate.generatego.txt \
543529
./api/v1alpha3 \
544530
./api/v1alpha4 \
545-
./$(EXP_DIR)/api/v1alpha3 \
546-
./$(EXP_DIR)/api/v1alpha4
531+
./exp/api/v1alpha3 \
532+
./exp/api/v1alpha4
547533

548534
.PHONY: generate-go-conversions-test-extension
549535
generate-go-conversions-test-extension: $(CONVERSION_GEN) ## Generate conversions go code for test runtime extension provider
@@ -552,7 +538,7 @@ generate-go-conversions-test-extension: $(CONVERSION_GEN) ## Generate conversion
552538
.PHONY: generate-go-openapi
553539
generate-go-openapi: $(OPENAPI_GEN) ## Generate openapi go code for runtime SDK
554540
@mkdir -p ./tmp/sigs.k8s.io; ln -s $(ROOT_DIR) ./tmp/sigs.k8s.io/; cd ./tmp; \
555-
for pkg in "api/core/v1beta2" "api/core/v1beta1" "$(EXP_DIR)/runtime/hooks/api/v1alpha1"; do \
541+
for pkg in "api/core/v1beta2" "api/core/v1beta1" "exp/runtime/hooks/api/v1alpha1"; do \
556542
(cd ../ && $(MAKE) clean-generated-openapi-definitions SRC_DIRS="./$${pkg}"); \
557543
echo "** Generating openapi schema for types in ./$${pkg} **"; \
558544
$(OPENAPI_GEN) \

api/core/v1beta1/condition_consts.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,14 @@ const (
358358
// if the references are up-to-date.
359359
ClusterClassRefVersionsUpToDateInternalErrorReason = "InternalError"
360360
)
361+
362+
// Conditions and condition Reasons for the MachinePool object.
363+
364+
const (
365+
// ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool.
366+
ReplicasReadyCondition ConditionType = "ReplicasReady"
367+
368+
// WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas
369+
// to be ready.
370+
WaitingForReplicasReadyReason = "WaitingForReplicasReady"
371+
)

api/core/v1beta1/conversion.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ func (dst *MachineHealthCheck) ConvertFrom(srcRaw conversion.Hub) error {
143143
return Convert_v1beta2_MachineHealthCheck_To_v1beta1_MachineHealthCheck(src, dst, nil)
144144
}
145145

146+
func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error {
147+
dst := dstRaw.(*clusterv1.MachinePool)
148+
149+
if err := Convert_v1beta1_MachinePool_To_v1beta2_MachinePool(src, dst, nil); err != nil {
150+
return err
151+
}
152+
153+
dst.Spec.Template.Spec.MinReadySeconds = src.Spec.MinReadySeconds
154+
155+
return nil
156+
}
157+
158+
func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error {
159+
src := srcRaw.(*clusterv1.MachinePool)
160+
161+
if err := Convert_v1beta2_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil {
162+
return err
163+
}
164+
165+
dst.Spec.MinReadySeconds = src.Spec.Template.Spec.MinReadySeconds
166+
167+
return nil
168+
}
169+
146170
func Convert_v1beta2_ClusterClassSpec_To_v1beta1_ClusterClassSpec(in *clusterv1.ClusterClassSpec, out *ClusterClassSpec, s apimachineryconversion.Scope) error {
147171
if err := autoConvert_v1beta2_ClusterClassSpec_To_v1beta1_ClusterClassSpec(in, out, s); err != nil {
148172
return err
@@ -763,3 +787,100 @@ func Convert_v1beta1_MachineSetSpec_To_v1beta2_MachineSetSpec(in *MachineSetSpec
763787
func Convert_v1beta2_MachineSpec_To_v1beta1_MachineSpec(in *clusterv1.MachineSpec, out *MachineSpec, s apimachineryconversion.Scope) error {
764788
return autoConvert_v1beta2_MachineSpec_To_v1beta1_MachineSpec(in, out, s)
765789
}
790+
791+
func Convert_v1beta2_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *clusterv1.MachinePoolStatus, out *MachinePoolStatus, s apimachineryconversion.Scope) error {
792+
if err := autoConvert_v1beta2_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in, out, s); err != nil {
793+
return err
794+
}
795+
796+
// Reset conditions from autogenerated conversions
797+
// NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1beta1).
798+
out.Conditions = nil
799+
800+
// Reset replica counters from autogenerated conversions
801+
// NOTE: replica counters with a new semantic should not be automatically be converted into old replica counters.
802+
out.ReadyReplicas = 0
803+
out.AvailableReplicas = 0
804+
805+
// Retrieve legacy conditions (v1beta1), failureReason, failureMessage and replica counters from the deprecated field.
806+
if in.Deprecated != nil && in.Deprecated.V1Beta1 != nil {
807+
if in.Deprecated.V1Beta1.Conditions != nil {
808+
Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1beta1_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions)
809+
}
810+
out.FailureReason = in.Deprecated.V1Beta1.FailureReason
811+
out.FailureMessage = in.Deprecated.V1Beta1.FailureMessage
812+
out.ReadyReplicas = in.Deprecated.V1Beta1.ReadyReplicas
813+
out.AvailableReplicas = in.Deprecated.V1Beta1.AvailableReplicas
814+
out.UnavailableReplicas = in.Deprecated.V1Beta1.UnavailableReplicas
815+
}
816+
817+
// Move initialization to old fields
818+
if in.Initialization != nil {
819+
out.BootstrapReady = in.Initialization.BootstrapDataSecretCreated
820+
out.InfrastructureReady = in.Initialization.InfrastructureProvisioned
821+
}
822+
823+
// Move new conditions (v1beta2) and replica counters to the v1beta2 field.
824+
if in.Conditions == nil && in.ReadyReplicas == nil && in.AvailableReplicas == nil && in.UpToDateReplicas == nil {
825+
return nil
826+
}
827+
out.V1Beta2 = &MachinePoolV1Beta2Status{}
828+
out.V1Beta2.Conditions = in.Conditions
829+
out.V1Beta2.ReadyReplicas = in.ReadyReplicas
830+
out.V1Beta2.AvailableReplicas = in.AvailableReplicas
831+
out.V1Beta2.UpToDateReplicas = in.UpToDateReplicas
832+
return nil
833+
}
834+
835+
func Convert_v1beta1_MachinePoolStatus_To_v1beta2_MachinePoolStatus(in *MachinePoolStatus, out *clusterv1.MachinePoolStatus, s apimachineryconversion.Scope) error {
836+
if err := autoConvert_v1beta1_MachinePoolStatus_To_v1beta2_MachinePoolStatus(in, out, s); err != nil {
837+
return err
838+
}
839+
840+
// Reset conditions from autogenerated conversions
841+
// NOTE: v1beta1 conditions should not be automatically be converted into v1beta2 conditions.
842+
out.Conditions = nil
843+
844+
// Reset replica counters from autogenerated conversions
845+
// NOTE: old replica counters should not be automatically be converted into replica counters with a new semantic.
846+
out.ReadyReplicas = nil
847+
out.AvailableReplicas = nil
848+
849+
// Retrieve new conditions (v1beta2) and replica counters from the v1beta2 field.
850+
if in.V1Beta2 != nil {
851+
out.Conditions = in.V1Beta2.Conditions
852+
out.ReadyReplicas = in.V1Beta2.ReadyReplicas
853+
out.AvailableReplicas = in.V1Beta2.AvailableReplicas
854+
out.UpToDateReplicas = in.V1Beta2.UpToDateReplicas
855+
}
856+
857+
// Move BootstrapReady and InfrastructureReady to Initialization
858+
if in.BootstrapReady || in.InfrastructureReady {
859+
if out.Initialization == nil {
860+
out.Initialization = &clusterv1.MachinePoolInitializationStatus{}
861+
}
862+
out.Initialization.BootstrapDataSecretCreated = in.BootstrapReady
863+
out.Initialization.InfrastructureProvisioned = in.InfrastructureReady
864+
}
865+
866+
// Move legacy conditions (v1beta1), failureReason, failureMessage and replica counters to the deprecated field.
867+
if out.Deprecated == nil {
868+
out.Deprecated = &clusterv1.MachinePoolDeprecatedStatus{}
869+
}
870+
if out.Deprecated.V1Beta1 == nil {
871+
out.Deprecated.V1Beta1 = &clusterv1.MachinePoolV1Beta1DeprecatedStatus{}
872+
}
873+
if in.Conditions != nil {
874+
Convert_v1beta1_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions)
875+
}
876+
out.Deprecated.V1Beta1.FailureReason = in.FailureReason
877+
out.Deprecated.V1Beta1.FailureMessage = in.FailureMessage
878+
out.Deprecated.V1Beta1.ReadyReplicas = in.ReadyReplicas
879+
out.Deprecated.V1Beta1.AvailableReplicas = in.AvailableReplicas
880+
out.Deprecated.V1Beta1.UnavailableReplicas = in.UnavailableReplicas
881+
return nil
882+
}
883+
884+
func Convert_v1beta1_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in *MachinePoolSpec, out *clusterv1.MachinePoolSpec, s apimachineryconversion.Scope) error {
885+
return autoConvert_v1beta1_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in, out, s)
886+
}

api/core/v1beta1/conversion_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestFuzzyConversion(t *testing.T) {
6666
Spoke: &MachineHealthCheck{},
6767
FuzzerFuncs: []fuzzer.FuzzerFuncs{MachineHealthCheckFuzzFuncs},
6868
}))
69+
t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
70+
Hub: &clusterv1.MachinePool{},
71+
Spoke: &MachinePool{},
72+
FuzzerFuncs: []fuzzer.FuzzerFuncs{MachinePoolFuzzFuncs},
73+
}))
6974
}
7075

7176
func ClusterFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
@@ -359,3 +364,44 @@ func spokeMachineHealthCheckStatus(in *MachineHealthCheckStatus, c fuzz.Continue
359364
}
360365
}
361366
}
367+
368+
func MachinePoolFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
369+
return []interface{}{
370+
hubMachinePoolStatus,
371+
spokeMachinePoolStatus,
372+
}
373+
}
374+
375+
func hubMachinePoolStatus(in *clusterv1.MachinePoolStatus, c fuzz.Continue) {
376+
c.FuzzNoCustom(in)
377+
// Always create struct with at least one mandatory fields.
378+
if in.Deprecated == nil {
379+
in.Deprecated = &clusterv1.MachinePoolDeprecatedStatus{}
380+
}
381+
if in.Deprecated.V1Beta1 == nil {
382+
in.Deprecated.V1Beta1 = &clusterv1.MachinePoolV1Beta1DeprecatedStatus{}
383+
}
384+
385+
// Drop empty structs with only omit empty fields.
386+
if in.Initialization != nil {
387+
if reflect.DeepEqual(in.Initialization, &clusterv1.MachinePoolInitializationStatus{}) {
388+
in.Initialization = nil
389+
}
390+
}
391+
392+
// nil becomes &0 after hub => spoke => hub conversion
393+
// This is acceptable as usually Replicas is set and controllers using older apiVersions are not writing MachineSet status.
394+
if in.Replicas == nil {
395+
in.Replicas = ptr.To(int32(0))
396+
}
397+
}
398+
399+
func spokeMachinePoolStatus(in *MachinePoolStatus, c fuzz.Continue) {
400+
c.FuzzNoCustom(in)
401+
// Drop empty structs with only omit empty fields.
402+
if in.V1Beta2 != nil {
403+
if reflect.DeepEqual(in.V1Beta2, &MachinePoolV1Beta2Status{}) {
404+
in.V1Beta2 = nil
405+
}
406+
}
407+
}

0 commit comments

Comments
 (0)