diff --git a/pkg/state/filter.go b/pkg/state/filter.go index 13d7e87b7..337f5e7aa 100644 --- a/pkg/state/filter.go +++ b/pkg/state/filter.go @@ -21,7 +21,6 @@ import ( "github.com/nmstate/kubernetes-nmstate/api/shared" "github.com/nmstate/kubernetes-nmstate/pkg/environment" - goyaml "gopkg.in/yaml.v2" yaml "sigs.k8s.io/yaml" ) @@ -116,9 +115,6 @@ func filterOut(currentState shared.State) (shared.State, error) { if err := yaml.Unmarshal(currentState.Raw, &state); err != nil { return currentState, err } - if err := normalizeInterfacesNames(currentState.Raw, &state); err != nil { - return currentState, err - } state.Interfaces = filterOutInterfaces(state.Interfaces) if state.Routes != nil { @@ -133,26 +129,3 @@ func filterOut(currentState shared.State) (shared.State, error) { return shared.NewState(string(filteredState)), nil } - -// normalizeInterfacesNames fixes the unmarshal of numeric values in the interfaces names -// Numeric values, including the ones with a base prefix (e.g. 0x123) should be stringify. -func normalizeInterfacesNames(rawState []byte, state *rootState) error { - var stateForNormalization rootState - if err := goyaml.Unmarshal(rawState, &stateForNormalization); err != nil { - return err - } - - for i, iface := range stateForNormalization.Interfaces { - state.Interfaces[i].Name = iface.Name - } - - if stateForNormalization.Routes != nil { - for i, route := range stateForNormalization.Routes.Config { - state.Routes.Config[i].NextHopInterface = route.NextHopInterface - } - for i, route := range stateForNormalization.Routes.Running { - state.Routes.Running[i].NextHopInterface = route.NextHopInterface - } - } - return nil -} diff --git a/pkg/state/filter_test.go b/pkg/state/filter_test.go index 609c182e3..71a0930bc 100644 --- a/pkg/state/filter_test.go +++ b/pkg/state/filter_test.go @@ -325,104 +325,4 @@ dns-resolver: Expect(returnedState).To(MatchYAML(state)) }) }) - - Context("when the interfaces have numeric characters", func() { - BeforeEach(func() { - state = nmstate.NewState(`interfaces: - - name: eth0 - type: ethernet - - name: '0' - type: veth - veth: - peer: eth2 - state: ignore - - name: '1101010' - type: veth - state: ignore - veth: - peer: eth2 - - name: '0.0' - type: veth - veth: - peer: eth2 - state: ignore - - name: '1.0' - type: veth - veth: - peer: eth2 - state: ignore - - name: '0xfe' - type: veth - veth: - peer: eth2 - state: ignore - - name: '60.e+02' - type: veth - veth: - peer: eth2 - state: ignore - - name: 10e+02 - type: veth - veth: - peer: eth2 - state: ignore - - name: 70e+02 - type: veth - veth: - peer: eth2 - state: ignore - - name: 94475496822e234 - type: veth - veth: - peer: eth2 - state: ignore -routes: - config: [] - running: - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: eth0 - table-id: 254 - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: 94475496822e234 - table-id: 254 - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: '94475496822e234' - table-id: 254 - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: 70e+02 - table-id: 254 - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: 60.e+02 - table-id: 254 -`) - filteredState = nmstate.NewState(`interfaces: -- name: eth0 - type: ethernet -routes: - config: [] - running: - - destination: fd10:244::8c40/128 - metric: 1024 - next-hop-address: 10.21.21.10 - next-hop-interface: eth0 - table-id: 254 -`) - }) - - It("should filter out interfaces correctly", func() { - returnedState, err := filterOut(state) - Expect(err).NotTo(HaveOccurred()) - Expect(returnedState).To(MatchYAML(filteredState)) - }) - }) })