-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b59abf
commit d401101
Showing
13 changed files
with
265 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package replicaset | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
v1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
) | ||
|
||
// GetActiveReplicaSet finds the replicaset that is serving traffic from the active service or returns nil | ||
func GetActiveReplicaSet(allRS []*appsv1.ReplicaSet, activeSelector string) *appsv1.ReplicaSet { | ||
if activeSelector == "" { | ||
return nil | ||
} | ||
for _, rs := range allRS { | ||
if rs == nil { | ||
continue | ||
} | ||
if podHash, ok := rs.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]; ok { | ||
if podHash == activeSelector { | ||
return rs | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func ReadyForPreview(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, allRSs []*appsv1.ReplicaSet) bool { | ||
newRSReplicaCount, err := NewRSNewReplicas(rollout, allRSs, newRS) | ||
if err != nil { | ||
return false | ||
} | ||
return *(newRS.Spec.Replicas) == newRSReplicaCount && | ||
newRS.Status.AvailableReplicas == newRSReplicaCount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package replicaset | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/pointer" | ||
|
||
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
) | ||
|
||
func TestGetActiveReplicaSet(t *testing.T) { | ||
assert.Nil(t, GetActiveReplicaSet(nil, "")) | ||
rs1 := &appsv1.ReplicaSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: "abcd"}, | ||
}, | ||
} | ||
assert.Nil(t, GetActiveReplicaSet([]*appsv1.ReplicaSet{rs1}, "1234")) | ||
|
||
rs2 := &appsv1.ReplicaSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: "1234"}, | ||
}, | ||
} | ||
assert.Equal(t, rs2, GetActiveReplicaSet([]*appsv1.ReplicaSet{nil, rs1, rs2}, "1234")) | ||
} | ||
|
||
func TestReadyForPreview(t *testing.T) { | ||
rollout := &v1alpha1.Rollout{ | ||
Spec: v1alpha1.RolloutSpec{ | ||
Strategy: v1alpha1.RolloutStrategy{ | ||
BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, | ||
}, | ||
}, | ||
} | ||
|
||
readyRS := &appsv1.ReplicaSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: "abcd"}, | ||
}, | ||
Spec: appsv1.ReplicaSetSpec{ | ||
Replicas: pointer.Int32Ptr(1), | ||
}, | ||
Status: appsv1.ReplicaSetStatus{ | ||
AvailableReplicas: 1, | ||
}, | ||
} | ||
|
||
notReadyRS := &appsv1.ReplicaSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: "abcd"}, | ||
}, | ||
Spec: appsv1.ReplicaSetSpec{ | ||
Replicas: pointer.Int32Ptr(1), | ||
}, | ||
Status: appsv1.ReplicaSetStatus{ | ||
AvailableReplicas: 0, | ||
}, | ||
} | ||
assert.False(t, ReadyForPreview(&v1alpha1.Rollout{}, nil, nil)) | ||
assert.True(t, ReadyForPreview(rollout, readyRS, []*appsv1.ReplicaSet{readyRS})) | ||
assert.False(t, ReadyForPreview(rollout, notReadyRS, []*appsv1.ReplicaSet{readyRS})) | ||
} |
Oops, something went wrong.