Skip to content

Commit

Permalink
probes: start http server for liveness early on (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
draychev authored and akshaysngupta committed Dec 4, 2019
1 parent 2bc0e40 commit bc90103
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
34 changes: 19 additions & 15 deletions cmd/appgw-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ func main() {
glog.Fatal(errorLine)
}

azClient := azure.NewAzClient(azure.SubscriptionID(env.SubscriptionID), azure.ResourceGroup(env.ResourceGroupName), azure.ResourceName(env.AppGwName))
appGwIdentifier := appgw.Identifier{
SubscriptionID: env.SubscriptionID,
ResourceGroup: env.ResourceGroupName,
AppGwName: env.AppGwName,
}

// create a new agic controller
appGwIngressController := controller.NewAppGwIngressController(azClient, appGwIdentifier, k8sContext, recorder, metricStore, agicPod)

// initialize the http server and start it
httpServer := httpserver.NewHTTPServer(
appGwIngressController,
metricStore,
env.HTTPServicePort)
httpServer.Start()

glog.V(3).Infof("App Gateway Details: Subscription: %s, Resource Group: %s, Name: %s", env.SubscriptionID, env.ResourceGroupName, env.AppGwName)

var authorizer autorest.Authorizer
Expand All @@ -138,9 +155,10 @@ func main() {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonARMAuthFailure, errorLine)
}
glog.Fatal(errorLine)
} else {
azClient.SetAuthorizer(authorizer)
}

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

appGwIdentifier := appgw.Identifier{
SubscriptionID: env.SubscriptionID,
ResourceGroup: env.ResourceGroupName,
AppGwName: env.AppGwName,
}

// namespace validations
if err := validateNamespaces(namespaces, kubeClient); err != nil {
glog.Fatal(err) // side-effect: will panic on non-existent namespace
Expand All @@ -197,8 +209,6 @@ func main() {
glog.Fatal(errorLine)
}

appGwIngressController := controller.NewAppGwIngressController(azClient, appGwIdentifier, k8sContext, recorder, metricStore, agicPod)

if err := appGwIngressController.Start(env); err != nil {
errorLine := fmt.Sprint("Could not start AGIC: ", err)
if agicPod != nil {
Expand All @@ -207,12 +217,6 @@ func main() {
glog.Fatal(errorLine)
}

httpServer := httpserver.NewHTTPServer(
appGwIngressController,
metricStore,
env.HTTPServicePort)
httpServer.Start()

sigChan := make(chan os.Signal)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan
Expand Down
28 changes: 13 additions & 15 deletions pkg/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

// AzClient is an interface for client to Azure
type AzClient interface {
SetAuthorizer(authorizer autorest.Authorizer)

GetGateway() (n.ApplicationGateway, error)
UpdateGateway(*n.ApplicationGateway) error
DeployGatewayWithVnet(ResourceGroup, ResourceName, ResourceName, string) error
Expand All @@ -36,7 +38,6 @@ type azClient struct {
subnetsClient n.SubnetsClient
groupsClient r.GroupsClient
deploymentsClient r.DeploymentsClient
authorizer autorest.Authorizer

subscriptionID SubscriptionID
resourceGroupName ResourceGroup
Expand All @@ -47,7 +48,7 @@ type azClient struct {
}

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

ctx: context.Background(),
authorizer: authorizer,
ctx: context.Background(),
}

if err := az.appGatewaysClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to App Gateway client: ", userAgent)
}
az.appGatewaysClient.Authorizer = az.authorizer

if err := az.publicIPsClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to Public IP client: ", userAgent)
}
az.publicIPsClient.Authorizer = az.authorizer

if err := az.virtualNetworksClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to Virtual Networks client: ", userAgent)
}
az.virtualNetworksClient.Authorizer = az.authorizer

if err := az.subnetsClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to Subnets client: ", userAgent)
}
az.subnetsClient.Authorizer = az.authorizer

if err := az.groupsClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to Groups client: ", userAgent)
}
az.groupsClient.Authorizer = az.authorizer

if err := az.deploymentsClient.AddToUserAgent(userAgent); err != nil {
glog.Error("Error adding User Agent to Deployments client: ", userAgent)
}
az.deploymentsClient.Authorizer = az.authorizer

return az
}

func (az *azClient) SetAuthorizer(authorizer autorest.Authorizer) {
az.appGatewaysClient.Authorizer = authorizer
az.publicIPsClient.Authorizer = authorizer
az.virtualNetworksClient.Authorizer = authorizer
az.subnetsClient.Authorizer = authorizer
az.groupsClient.Authorizer = authorizer
az.deploymentsClient.Authorizer = authorizer
}

func (az *azClient) GetGateway() (n.ApplicationGateway, error) {
return az.appGatewaysClient.Get(az.ctx, string(az.resourceGroupName), string(az.appGwName))
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/azure/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

package azure

import n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
import (
"github.com/Azure/go-autorest/autorest"

n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
)

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

// SetAuthorizer is an empty function
func (az *FakeAzClient) SetAuthorizer(authorizer autorest.Authorizer) {
}

// GetGateway runs GetGatewayFunc and return a gateway
func (az *FakeAzClient) GetGateway() (n.ApplicationGateway, error) {
if az.GetGatewayFunc != nil {
Expand Down

0 comments on commit bc90103

Please sign in to comment.