Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: lubronzhan <lubronzhan@gmail.com>
  • Loading branch information
lubronzhan committed Jan 30, 2024
1 parent 539ad9c commit 9fb7a89
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
27 changes: 27 additions & 0 deletions exp/runtime/topologymutation/errors.go
Original file line number Diff line number Diff line change
@@ -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)
}
7 changes: 1 addition & 6 deletions exp/runtime/topologymutation/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions exp/runtime/topologymutation/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9fb7a89

Please sign in to comment.