@@ -10,6 +10,7 @@ import (
1010 "github.com/pkg/errors"
1111 troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
1212 appsv1 "k8s.io/api/apps/v1"
13+ "k8s.io/apimachinery/pkg/labels"
1314)
1415
1516func analyzeReplicaSetStatus (analyzer * troubleshootv1beta2.ReplicaSetStatus , getFileContents func (string ) (map [string ][]byte , error )) ([]* AnalyzeResult , error ) {
@@ -74,6 +75,11 @@ func analyzeAllReplicaSetStatuses(analyzer *troubleshootv1beta2.ReplicaSetStatus
7475 return nil , errors .Wrap (err , "failed to read collected replicaset from file" )
7576 }
7677
78+ labelSelector , err := labels .Parse (strings .Join (analyzer .Selector , "," ))
79+ if err != nil {
80+ return nil , errors .Wrap (err , "failed to parse selector" )
81+ }
82+
7783 results := []* AnalyzeResult {}
7884 for _ , collected := range files {
7985 var replicasets []appsv1.ReplicaSet
@@ -82,20 +88,31 @@ func analyzeAllReplicaSetStatuses(analyzer *troubleshootv1beta2.ReplicaSetStatus
8288 }
8389
8490 for _ , replicaset := range replicasets {
85- if replicaset . Spec . Replicas == nil && replicaset .Status . AvailableReplicas == 1 { // default is 1
91+ if ! labelSelector . Matches ( labels . Set ( replicaset .Labels )) {
8692 continue
8793 }
8894
89- if replicaset .Spec .Replicas != nil && * replicaset .Spec .Replicas == replicaset .Status .AvailableReplicas {
90- continue
91- }
92-
93- result := & AnalyzeResult {
94- Title : fmt .Sprintf ("%s/%s ReplicaSet Status" , replicaset .Namespace , replicaset .Name ),
95- IconKey : "kubernetes_deployment_status" , // TODO: need new icon
96- IconURI : "https://troubleshoot.sh/images/analyzer-icons/deployment-status.svg?w=17&h=17" , // TODO: need new icon
97- IsFail : true ,
98- Message : fmt .Sprintf ("The replicaset %s/%s is not ready" , replicaset .Namespace , replicaset .Name ),
95+ var result * AnalyzeResult
96+ if len (analyzer .Outcomes ) > 0 {
97+ result , err = replicasetStatus (analyzer .Outcomes , & replicaset )
98+ if err != nil {
99+ return nil , errors .Wrap (err , "failed to process status" )
100+ }
101+ } else {
102+ if replicaset .Spec .Replicas == nil && replicaset .Status .AvailableReplicas == 1 { // default is 1
103+ continue
104+ }
105+ if replicaset .Spec .Replicas != nil && * replicaset .Spec .Replicas == replicaset .Status .AvailableReplicas {
106+ continue
107+ }
108+
109+ result = & AnalyzeResult {
110+ Title : fmt .Sprintf ("%s/%s ReplicaSet Status" , replicaset .Namespace , replicaset .Name ),
111+ IconKey : "kubernetes_deployment_status" , // TODO: need new icon
112+ IconURI : "https://troubleshoot.sh/images/analyzer-icons/deployment-status.svg?w=17&h=17" , // TODO: need new icon
113+ IsFail : true ,
114+ Message : fmt .Sprintf ("The replicaset %s/%s is not ready" , replicaset .Namespace , replicaset .Name ),
115+ }
99116 }
100117
101118 results = append (results , result )
0 commit comments