Skip to content

Commit f23dacc

Browse files
authored
Disable pruning for istios that potentially manage external revs (#654)
Signed-off-by: Nick Fox <[email protected]>
1 parent 84c35a1 commit f23dacc

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

controllers/istio/istio_controller.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,22 @@ func (r *Reconciler) doReconcile(ctx context.Context, istio *v1.Istio) (result c
9191
return ctrl.Result{}, err
9292
}
9393

94-
return revision.PruneInactive(ctx, r.Client, istio.UID, getActiveRevisionName(istio), getPruningGracePeriod(istio))
94+
// We cannot prune revisions that manage an external cluster because the operator currently
95+
// has no way of knowing if the revision is still in use on the external cluster.
96+
if !managesExternalRevision(istio) {
97+
return revision.PruneInactive(ctx, r.Client, istio.UID, getActiveRevisionName(istio), getPruningGracePeriod(istio))
98+
}
99+
100+
return
101+
}
102+
103+
func managesExternalRevision(istio *v1.Istio) bool {
104+
if values := istio.Spec.Values; values != nil {
105+
if pilot := values.Pilot; pilot != nil {
106+
return pilot.Env["EXTERNAL_ISTIOD"] == "true"
107+
}
108+
}
109+
return false
95110
}
96111

97112
func validate(istio *v1.Istio) error {

controllers/istio/istio_controller_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,47 @@ func TestGetPruningGracePeriod(t *testing.T) {
872872
}
873873
}
874874

875+
func TestManagesExternalRevision(t *testing.T) {
876+
tests := []struct {
877+
name string
878+
spec v1.IstioSpec
879+
expected bool
880+
}{
881+
{
882+
name: "Empty spec.values does not manage",
883+
spec: v1.IstioSpec{},
884+
expected: false,
885+
},
886+
{
887+
name: "Empty spec.values.pilot does not manage",
888+
spec: v1.IstioSpec{Values: &v1.Values{}},
889+
expected: false,
890+
},
891+
{
892+
name: "Empty spec.values.pilot.env does not manage",
893+
spec: v1.IstioSpec{Values: &v1.Values{Pilot: &v1.PilotConfig{}}},
894+
expected: false,
895+
},
896+
{
897+
name: "env with EXTERNAL_ISTIOD=true does manage",
898+
spec: v1.IstioSpec{Values: &v1.Values{Pilot: &v1.PilotConfig{Env: map[string]string{"EXTERNAL_ISTIOD": "true"}}}},
899+
expected: true,
900+
},
901+
}
902+
903+
for _, tt := range tests {
904+
t.Run(tt.name, func(t *testing.T) {
905+
istio := &v1.Istio{
906+
Spec: tt.spec,
907+
}
908+
got := managesExternalRevision(istio)
909+
if got != tt.expected {
910+
t.Errorf("managesExternalRevision() = %v, want %v", got, tt.expected)
911+
}
912+
})
913+
}
914+
}
915+
875916
func Must(t *testing.T, err error) {
876917
t.Helper()
877918
if err != nil {

0 commit comments

Comments
 (0)