-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating with fixes #258
Updating with fixes #258
Changes from 3 commits
1f7d729
49cd71a
b826e36
8e54dda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package clusters | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
@@ -10,13 +11,14 @@ import ( | |
|
||
"github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/model" | ||
istiofake "istio.io/client-go/pkg/clientset/versioned/fake" | ||
|
||
"os" | ||
argo "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
v1 "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1" | ||
admiralFake "github.com/istio-ecosystem/admiral/admiral/pkg/client/clientset/versioned/fake" | ||
"github.com/istio-ecosystem/admiral/admiral/pkg/controller/admiral" | ||
"github.com/istio-ecosystem/admiral/admiral/pkg/controller/common" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
v12 "k8s.io/api/apps/v1" | ||
v13 "k8s.io/api/core/v1" | ||
|
@@ -454,3 +456,84 @@ func TestRoutingPolicyHandler(t *testing.T) { | |
assert.Nil(t, registry.AdmiralCache.RoutingPolicyFilterCache.Get("bar3stage")) | ||
|
||
} | ||
|
||
func TestRoutingPolicyReadOnly(t *testing.T) { | ||
p := common.AdmiralParams{ | ||
KubeconfigPath: "testdata/fake.config", | ||
LabelSet: &common.LabelSet{}, | ||
EnableSAN: true, | ||
SANPrefix: "prefix", | ||
HostnameSuffix: "mesh", | ||
SyncNamespace: "ns", | ||
CacheRefreshDuration: time.Minute, | ||
ClusterRegistriesNamespace: "default", | ||
DependenciesNamespace: "default", | ||
SecretResolver: "", | ||
EnableRoutingPolicy: true, | ||
EnvoyFilterVersion: "1.13", | ||
} | ||
|
||
p.LabelSet.WorkloadIdentityKey = "identity" | ||
p.LabelSet.EnvKey = "admiral.io/env" | ||
p.LabelSet.GlobalTrafficDeploymentLabel = "identity" | ||
|
||
handler := RoutingPolicyHandler{} | ||
|
||
testcases := []struct { | ||
name string | ||
rp *v1.RoutingPolicy | ||
readOnly bool | ||
doesError bool | ||
}{ | ||
{ | ||
name: "Readonly test - Routing Policy", | ||
rp: &v1.RoutingPolicy{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: remove extra line. |
||
}, | ||
readOnly: true, | ||
doesError: true, | ||
}, | ||
{ | ||
name: "Readonly false test - Routing Policy", | ||
rp: &v1.RoutingPolicy{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: remove extra line. |
||
}, | ||
readOnly: false, | ||
doesError: false, | ||
}, | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
for _, c := range testcases { | ||
t.Run(c.name, func(t *testing.T) { | ||
if c.readOnly { | ||
CurrentAdmiralState.ReadOnly = true | ||
}else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: space before/after else. |
||
CurrentAdmiralState.ReadOnly = false | ||
} | ||
var buf bytes.Buffer | ||
log.SetOutput(&buf) | ||
defer func() { | ||
log.SetOutput(os.Stderr) | ||
}() | ||
// Add routing policy test | ||
handler.Added(ctx, c.rp) | ||
t.Log(buf.String()) | ||
val := strings.Contains(buf.String(),"skipping read-only mode") | ||
assert.Equal(t, c.doesError,val) | ||
|
||
// Update routing policy test | ||
handler.Updated(ctx, c.rp) | ||
t.Log(buf.String()) | ||
val = strings.Contains(buf.String(),"skipping read-only mode") | ||
assert.Equal(t, c.doesError,val) | ||
|
||
// Delete routing policy test | ||
handler.Deleted(ctx, c.rp) | ||
t.Log(buf.String()) | ||
val = strings.Contains(buf.String(),"skipping read-only mode") | ||
assert.Equal(t, c.doesError,val) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check for nil here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops let me add that, its a check in quarter master so that should work