diff --git a/exp/runtime/topologymutation/errors.go b/exp/runtime/topologymutation/errors.go new file mode 100644 index 000000000000..ccd574ba9cfc --- /dev/null +++ b/exp/runtime/topologymutation/errors.go @@ -0,0 +1,27 @@ +/* +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 topologymutation + +import ( + patchvariables "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/patches/variables" +) + +// IsNotFoundError checks if the passed error is a notFoundError. +// It exposes same function in internal package so that user can directly call. +func IsNotFoundError(err error) bool { + return patchvariables.IsNotFoundError(err) +} diff --git a/exp/runtime/topologymutation/variables.go b/exp/runtime/topologymutation/variables.go index 8103f66fb7f8..1b7941217a84 100644 --- a/exp/runtime/topologymutation/variables.go +++ b/exp/runtime/topologymutation/variables.go @@ -60,13 +60,8 @@ func GetBoolVariable(templateVariables map[string]apiextensionsv1.JSON, variable return false, err } - // Unquote the JSON string. - stringValue, err := strconv.Unquote(string(value.Raw)) - if err != nil { - return false, err - } // Parse the JSON bool. - boolValue, err := strconv.ParseBool(stringValue) + boolValue, err := strconv.ParseBool(string(value.Raw)) if err != nil { return false, err } diff --git a/exp/runtime/topologymutation/variables_test.go b/exp/runtime/topologymutation/variables_test.go index b62a715cf833..dbcb23fb2ed8 100644 --- a/exp/runtime/topologymutation/variables_test.go +++ b/exp/runtime/topologymutation/variables_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" patchvariables "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/patches/variables" ) @@ -143,7 +143,7 @@ func Test_GetStringTemplateVariable(t *testing.T) { func Test_GetBoolVariable(t *testing.T) { g := NewWithT(t) - varA := apiextensionsv1.JSON{Raw: toJSON("true")} + varA := apiextensionsv1.JSON{Raw: []byte(`true`)} tests := []struct { name string variables map[string]apiextensionsv1.JSON @@ -258,7 +258,7 @@ func Test_GetVariableObjectWithNestedType(t *testing.T) { expectedErr: false, object: &Network{}, expectedVariableObject: Network{ - Ipv6Primary: pointer.Bool(true), + Ipv6Primary: ptr.To(true), AddressesFromPools: &[]AddressesFromPool{ { Name: "name",