-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Bueringer <[email protected]>
- Loading branch information
1 parent
2ebdffb
commit a3efe9d
Showing
13 changed files
with
266 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The following patch adds a directive for certmanager to inject CA into the CRD | ||
# CRD conversion requires k8s 1.13 or later. | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) | ||
name: machinepools.cluster.x-k8s.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# The following patch enables conversion webhook for CRD | ||
# CRD conversion requires k8s 1.13 or later. | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: machinepools.cluster.x-k8s.io | ||
spec: | ||
conversion: | ||
strategy: Webhook | ||
webhook: | ||
conversionReviewVersions: ["v1", "v1beta1"] | ||
clientConfig: | ||
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, | ||
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) | ||
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright 2021 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 v1alpha3 | ||
|
||
import ( | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer" | ||
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" | ||
clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1beta1" | ||
utilconversion "sigs.k8s.io/cluster-api/util/conversion" | ||
) | ||
|
||
func TestFuzzyConversion(t *testing.T) { | ||
t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ | ||
Hub: &clusterv1exp.MachinePool{}, | ||
Spoke: &MachinePool{}, | ||
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs}, | ||
})) | ||
} | ||
|
||
func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} { | ||
return []interface{}{ | ||
BootstrapFuzzer, | ||
MachinePoolSpecFuzzer, | ||
ObjectMetaFuzzer, | ||
} | ||
} | ||
|
||
func BootstrapFuzzer(obj *clusterv1.Bootstrap, c fuzz.Continue) { | ||
c.FuzzNoCustom(obj) | ||
|
||
// Bootstrap.Data has been removed in v1alpha4, so setting it to nil in order to avoid v1alpha3 --> <hub> --> v1alpha3 round trip errors. | ||
obj.Data = nil | ||
} | ||
|
||
func ObjectMetaFuzzer(in *clusterv1.ObjectMeta, c fuzz.Continue) { | ||
c.FuzzNoCustom(in) | ||
|
||
// These fields have been removed in v1beta1 | ||
// data is going to be lost, so we're forcing zero values here. | ||
in.Name = "" | ||
in.GenerateName = "" | ||
in.Namespace = "" | ||
in.OwnerReferences = nil | ||
} | ||
|
||
func MachinePoolSpecFuzzer(in *MachinePoolSpec, c fuzz.Continue) { | ||
c.Fuzz(in) | ||
|
||
// These fields have been removed in v1beta1 | ||
// data is going to be lost, so we're forcing zero values here. | ||
in.Strategy = nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2021 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 v1alpha4 | ||
|
||
import ( | ||
v1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
) | ||
|
||
func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*v1beta1.MachinePool) | ||
|
||
return Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil) | ||
} | ||
|
||
func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*v1beta1.MachinePool) | ||
|
||
return Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil) | ||
} | ||
|
||
func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*v1beta1.MachinePoolList) | ||
|
||
return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil) | ||
} | ||
|
||
func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*v1beta1.MachinePoolList) | ||
|
||
return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(src, dst, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2021 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 v1alpha4 | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer" | ||
clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1beta1" | ||
utilconversion "sigs.k8s.io/cluster-api/util/conversion" | ||
) | ||
|
||
func TestFuzzyConversion(t *testing.T) { | ||
t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ | ||
Hub: &clusterv1exp.MachinePool{}, | ||
Spoke: &MachinePool{}, | ||
FuzzerFuncs: []fuzzer.FuzzerFuncs{}, | ||
})) | ||
} |
Oops, something went wrong.