Skip to content

Commit bc90103

Browse files
Delyan Raychevakshaysngupta
authored andcommitted
probes: start http server for liveness early on (#674)
1 parent 2bc0e40 commit bc90103

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

cmd/appgw-ingress/main.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ func main() {
129129
glog.Fatal(errorLine)
130130
}
131131

132+
azClient := azure.NewAzClient(azure.SubscriptionID(env.SubscriptionID), azure.ResourceGroup(env.ResourceGroupName), azure.ResourceName(env.AppGwName))
133+
appGwIdentifier := appgw.Identifier{
134+
SubscriptionID: env.SubscriptionID,
135+
ResourceGroup: env.ResourceGroupName,
136+
AppGwName: env.AppGwName,
137+
}
138+
139+
// create a new agic controller
140+
appGwIngressController := controller.NewAppGwIngressController(azClient, appGwIdentifier, k8sContext, recorder, metricStore, agicPod)
141+
142+
// initialize the http server and start it
143+
httpServer := httpserver.NewHTTPServer(
144+
appGwIngressController,
145+
metricStore,
146+
env.HTTPServicePort)
147+
httpServer.Start()
148+
132149
glog.V(3).Infof("App Gateway Details: Subscription: %s, Resource Group: %s, Name: %s", env.SubscriptionID, env.ResourceGroupName, env.AppGwName)
133150

134151
var authorizer autorest.Authorizer
@@ -138,9 +155,10 @@ func main() {
138155
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonARMAuthFailure, errorLine)
139156
}
140157
glog.Fatal(errorLine)
158+
} else {
159+
azClient.SetAuthorizer(authorizer)
141160
}
142161

143-
azClient := azure.NewAzClient(azure.SubscriptionID(env.SubscriptionID), azure.ResourceGroup(env.ResourceGroupName), azure.ResourceName(env.AppGwName), authorizer)
144162
if err = azure.WaitForAzureAuth(azClient, maxAuthRetryCount, retryPause); err != nil {
145163
if err == azure.ErrAppGatewayNotFound && env.EnableDeployAppGateway {
146164
if env.AppGwSubnetID != "" {
@@ -165,12 +183,6 @@ func main() {
165183
}
166184
}
167185

168-
appGwIdentifier := appgw.Identifier{
169-
SubscriptionID: env.SubscriptionID,
170-
ResourceGroup: env.ResourceGroupName,
171-
AppGwName: env.AppGwName,
172-
}
173-
174186
// namespace validations
175187
if err := validateNamespaces(namespaces, kubeClient); err != nil {
176188
glog.Fatal(err) // side-effect: will panic on non-existent namespace
@@ -197,8 +209,6 @@ func main() {
197209
glog.Fatal(errorLine)
198210
}
199211

200-
appGwIngressController := controller.NewAppGwIngressController(azClient, appGwIdentifier, k8sContext, recorder, metricStore, agicPod)
201-
202212
if err := appGwIngressController.Start(env); err != nil {
203213
errorLine := fmt.Sprint("Could not start AGIC: ", err)
204214
if agicPod != nil {
@@ -207,12 +217,6 @@ func main() {
207217
glog.Fatal(errorLine)
208218
}
209219

210-
httpServer := httpserver.NewHTTPServer(
211-
appGwIngressController,
212-
metricStore,
213-
env.HTTPServicePort)
214-
httpServer.Start()
215-
216220
sigChan := make(chan os.Signal)
217221
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
218222
<-sigChan

pkg/azure/client.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121

2222
// AzClient is an interface for client to Azure
2323
type AzClient interface {
24+
SetAuthorizer(authorizer autorest.Authorizer)
25+
2426
GetGateway() (n.ApplicationGateway, error)
2527
UpdateGateway(*n.ApplicationGateway) error
2628
DeployGatewayWithVnet(ResourceGroup, ResourceName, ResourceName, string) error
@@ -36,7 +38,6 @@ type azClient struct {
3638
subnetsClient n.SubnetsClient
3739
groupsClient r.GroupsClient
3840
deploymentsClient r.DeploymentsClient
39-
authorizer autorest.Authorizer
4041

4142
subscriptionID SubscriptionID
4243
resourceGroupName ResourceGroup
@@ -47,7 +48,7 @@ type azClient struct {
4748
}
4849

4950
// NewAzClient returns an Azure Client
50-
func NewAzClient(subscriptionID SubscriptionID, resourceGroupName ResourceGroup, appGwName ResourceName, authorizer autorest.Authorizer) AzClient {
51+
func NewAzClient(subscriptionID SubscriptionID, resourceGroupName ResourceGroup, appGwName ResourceName) AzClient {
5152
settings, err := auth.GetSettingsFromEnvironment()
5253
if err != nil {
5354
return nil
@@ -67,43 +68,40 @@ func NewAzClient(subscriptionID SubscriptionID, resourceGroupName ResourceGroup,
6768
appGwName: appGwName,
6869
memoizedIPs: make(map[string]n.PublicIPAddress),
6970

70-
ctx: context.Background(),
71-
authorizer: authorizer,
71+
ctx: context.Background(),
7272
}
7373

7474
if err := az.appGatewaysClient.AddToUserAgent(userAgent); err != nil {
7575
glog.Error("Error adding User Agent to App Gateway client: ", userAgent)
7676
}
77-
az.appGatewaysClient.Authorizer = az.authorizer
78-
7977
if err := az.publicIPsClient.AddToUserAgent(userAgent); err != nil {
8078
glog.Error("Error adding User Agent to Public IP client: ", userAgent)
8179
}
82-
az.publicIPsClient.Authorizer = az.authorizer
83-
8480
if err := az.virtualNetworksClient.AddToUserAgent(userAgent); err != nil {
8581
glog.Error("Error adding User Agent to Virtual Networks client: ", userAgent)
8682
}
87-
az.virtualNetworksClient.Authorizer = az.authorizer
88-
8983
if err := az.subnetsClient.AddToUserAgent(userAgent); err != nil {
9084
glog.Error("Error adding User Agent to Subnets client: ", userAgent)
9185
}
92-
az.subnetsClient.Authorizer = az.authorizer
93-
9486
if err := az.groupsClient.AddToUserAgent(userAgent); err != nil {
9587
glog.Error("Error adding User Agent to Groups client: ", userAgent)
9688
}
97-
az.groupsClient.Authorizer = az.authorizer
98-
9989
if err := az.deploymentsClient.AddToUserAgent(userAgent); err != nil {
10090
glog.Error("Error adding User Agent to Deployments client: ", userAgent)
10191
}
102-
az.deploymentsClient.Authorizer = az.authorizer
10392

10493
return az
10594
}
10695

96+
func (az *azClient) SetAuthorizer(authorizer autorest.Authorizer) {
97+
az.appGatewaysClient.Authorizer = authorizer
98+
az.publicIPsClient.Authorizer = authorizer
99+
az.virtualNetworksClient.Authorizer = authorizer
100+
az.subnetsClient.Authorizer = authorizer
101+
az.groupsClient.Authorizer = authorizer
102+
az.deploymentsClient.Authorizer = authorizer
103+
}
104+
107105
func (az *azClient) GetGateway() (n.ApplicationGateway, error) {
108106
return az.appGatewaysClient.Get(az.ctx, string(az.resourceGroupName), string(az.appGwName))
109107
}

pkg/azure/fake.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
package azure
77

8-
import n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
8+
import (
9+
"github.com/Azure/go-autorest/autorest"
10+
11+
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
12+
)
913

1014
// GetGatewayFunc is a function type
1115
type GetGatewayFunc func() (n.ApplicationGateway, error)
@@ -32,6 +36,10 @@ func NewFakeAzClient() *FakeAzClient {
3236
return &FakeAzClient{}
3337
}
3438

39+
// SetAuthorizer is an empty function
40+
func (az *FakeAzClient) SetAuthorizer(authorizer autorest.Authorizer) {
41+
}
42+
3543
// GetGateway runs GetGatewayFunc and return a gateway
3644
func (az *FakeAzClient) GetGateway() (n.ApplicationGateway, error) {
3745
if az.GetGatewayFunc != nil {

0 commit comments

Comments
 (0)