Skip to content

Commit

Permalink
update test & fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Nov 30, 2023
1 parent 9fe636a commit f052a5c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func TestVirtualServiceIndexer(t *testing.T) {
opt := opts[0].(*client.ListOptions)
assert.Equal(t, &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(vsi.IndexName(), "vs"),
Namespace: "ns",
}, opt)

policy := cache[vsi.IndexName()]["vs"].(*mosniov1.HTTPFilterPolicy)
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/translation/final_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type FinalState struct {
EnvoyFilters map[string]*istiov1a3.EnvoyFilter
}

func toFinalState(ctx *Ctx, state *mergedState) (*FinalState, error) {
func toFinalState(_ *Ctx, state *mergedState) (*FinalState, error) {
efs := istio.DefaultEnvoyFilters()
hosts := []*mergedHostPolicy{}
for _, host := range state.Hosts {
Expand Down
9 changes: 3 additions & 6 deletions controller/internal/translation/merged_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ func toMergedState(ctx *Ctx, state *dataPlaneState) (*FinalState, error) {
// 2. If multiple polices configure the same plugin, the oldest one (based on creation timestamp) wins.
// 3. If there are multiple oldest polices, the one appearing first in alphabetical order by {namespace}/{name} wins.
mergedPolicy := host.Policies[0]
fmc, err := translateHTTPFilterPolicyToFilterManagerConfig(mergedPolicy)
if err != nil {
return nil, err
}
fmc := translateHTTPFilterPolicyToFilterManagerConfig(mergedPolicy)
mh.Policy = fmc
s.Hosts[name] = mh
}

return toFinalState(ctx, s)
}

func translateHTTPFilterPolicyToFilterManagerConfig(policy *mosniov1.HTTPFilterPolicy) (*filtermanager.FilterManagerConfig, error) {
func translateHTTPFilterPolicyToFilterManagerConfig(policy *mosniov1.HTTPFilterPolicy) *filtermanager.FilterManagerConfig {
fmc := &filtermanager.FilterManagerConfig{
Plugins: []*filtermanager.FilterConfig{},
}
Expand All @@ -71,5 +68,5 @@ func translateHTTPFilterPolicyToFilterManagerConfig(policy *mosniov1.HTTPFilterP
sort.Slice(fmc.Plugins, func(i, j int) bool {
return plugins.ComparePluginOrder(fmc.Plugins[i].Name, fmc.Plugins[j].Name)
})
return fmc, nil
return fmc
}
7 changes: 1 addition & 6 deletions controller/internal/translation/translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ func mustUnmarshal(t *testing.T, fn string, out interface{}) {
}

type testInput struct {
// we use sigs.k8s.io/yaml which uses JSON under the hover
HTTPFilterPolicy []*mosniov1.HTTPFilterPolicy `json:"httpFilterPolicy"`
VirtualService map[string][]*istiov1b1.VirtualService `json:"virtualService"`
Gateway map[string][]*istiov1b1.Gateway `json:"gateway"`
}

type testOutput struct {
// we use sigs.k8s.io/yaml which uses JSON under the hover
ToUpdate []*istiov1a3.EnvoyFilter `json:"toUpdate,omitempty"`
ToDelete []*istiov1a3.EnvoyFilter `json:"toDelete,omitempty"`
}

func TestTranslate(t *testing.T) {
inputFiles, err := filepath.Glob(filepath.Join("testdata", "translation", "*.in.yml"))
require.NoError(t, err)
Expand Down

0 comments on commit f052a5c

Please sign in to comment.