@@ -18,6 +18,14 @@ import (
18
18
"github.com/spf13/cobra"
19
19
)
20
20
21
+ const (
22
+ FederationStatusHealthy string = "Healthy"
23
+ FederationStatusUnhealthy string = "Unhealthy"
24
+
25
+ FederationStatusReasonNoBundleFound string = "No bundle found"
26
+ FederationStatusReasonBundlesDoNotMatch string = "Bundles do not match"
27
+ )
28
+
21
29
type FederationCommand struct {
22
30
cmdCtx * cmdcontext.CommandContext
23
31
}
@@ -84,7 +92,7 @@ func (c *FederationCommand) GetListCommand() *cobra.Command {
84
92
return err
85
93
}
86
94
87
- status , err := checkFederationStatus (cmd .Context (), kubeConfig , from , to )
95
+ status , reason , err := checkFederationStatus (cmd .Context (), kubeConfig , from , to )
88
96
if err != nil {
89
97
return err
90
98
}
@@ -93,11 +101,12 @@ func (c *FederationCommand) GetListCommand() *cobra.Command {
93
101
federation .From ,
94
102
federation .To ,
95
103
status ,
104
+ reason ,
96
105
}
97
106
}
98
107
99
108
table := tablewriter .NewWriter (os .Stdout )
100
- table .SetHeader ([]string {"From Trust Zone" , "To Trust Zone" , "Status" })
109
+ table .SetHeader ([]string {"From Trust Zone" , "To Trust Zone" , "Status" , "Reason" })
101
110
table .SetBorder (false )
102
111
table .AppendBulk (data )
103
112
table .Render ()
@@ -115,24 +124,24 @@ type bundles struct {
115
124
116
125
// checkFederationStatus builds a comparison map between two trust domains, retrieves there server CA bundle and any federated bundles available
117
126
// locally from the SPIRE server, and then compares the bundles on each to verify SPIRE has the correct bundles on each side of the federation
118
- func checkFederationStatus (ctx context.Context , kubeConfig string , from * trust_zone_proto.TrustZone , to * trust_zone_proto.TrustZone ) (string , error ) {
127
+ func checkFederationStatus (ctx context.Context , kubeConfig string , from * trust_zone_proto.TrustZone , to * trust_zone_proto.TrustZone ) (string , string , error ) {
119
128
compare := make (map [* trust_zone_proto.TrustZone ]bundles )
120
129
121
130
for _ , tz := range []* trust_zone_proto.TrustZone {from , to } {
122
131
if deployed , err := isTrustZoneDeployed (ctx , tz ); err != nil {
123
- return "" , err
132
+ return "" , "" , err
124
133
} else if ! deployed {
125
- return "Inactive" , nil
134
+ return "Inactive" , "" , nil
126
135
}
127
136
128
137
client , err := kubeutil .NewKubeClientFromSpecifiedContext (kubeConfig , tz .GetKubernetesContext ())
129
138
if err != nil {
130
- return "" , err
139
+ return "" , "" , err
131
140
}
132
141
133
142
serverCABundle , federatedBundles , err := spire .GetServerCABundleAndFederatedBundles (ctx , client )
134
143
if err != nil {
135
- return "" , err
144
+ return "" , "" , err
136
145
}
137
146
138
147
compare [tz ] = bundles {
@@ -144,15 +153,15 @@ func checkFederationStatus(ctx context.Context, kubeConfig string, from *trust_z
144
153
// Bundle does not exist at all on opposite trust domain
145
154
_ , ok := compare [from ].federatedBundles [to .TrustDomain ]
146
155
if ! ok {
147
- return "Unhealthy" , nil
156
+ return FederationStatusUnhealthy , FederationStatusReasonNoBundleFound , nil
148
157
}
149
158
150
159
// Bundle does not match entry on opposite trust domain
151
160
if compare [from ].federatedBundles [to .TrustDomain ] != compare [to ].serverCABundle {
152
- return "Unhealthy" , nil
161
+ return FederationStatusUnhealthy , FederationStatusReasonBundlesDoNotMatch , nil
153
162
}
154
163
155
- return "Healthy " , nil
164
+ return FederationStatusHealthy , " " , nil
156
165
}
157
166
158
167
// isTrustZoneDeployed returns whether a trust zone has been deployed, i.e. whether a SPIRE Helm release has been installed.
0 commit comments