Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewCrdRequestController(restService *restserver.HTTPRestService, kubeconfig
// StartRequestController starts the Reconciler loop which watches for CRD status updates
// Blocks until SIGINT or SIGTERM is received
// Notifies exitChan when kill signal received
func (crdRC *crdRequestController) StartRequestController(exitChan chan bool) error {
func (crdRC *crdRequestController) StartRequestController(exitChan <-chan struct{}) error {
var (
err error
)
Expand All @@ -154,7 +154,7 @@ func (crdRC *crdRequestController) StartRequestController(exitChan chan bool) er
}

logger.Printf("Starting reconcile loop")
if err := crdRC.mgr.Start(SetupSignalHandler(exitChan)); err != nil {
if err := crdRC.mgr.Start(exitChan); err != nil {
if crdRC.isNotDefined(err) {
logger.Errorf("[cns-rc] CRD is not defined on cluster, starting reconcile loop failed: %v", err)
os.Exit(1)
Expand Down
35 changes: 0 additions & 35 deletions cns/requestcontroller/kubecontroller/signalhandler.go

This file was deleted.

2 changes: 1 addition & 1 deletion cns/requestcontroller/requestcontrollerintreface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (

// RequestController interface for cns to interact with the request controller
type RequestController interface {
StartRequestController(exitChan chan bool) error
StartRequestController(exitChan <-chan struct{}) error
UpdateCRDSpec(cntxt context.Context, crdSpec nnc.NodeNetworkConfigSpec) error
}
44 changes: 44 additions & 0 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/Azure/azure-container-networking/cns/configuration"
"github.com/Azure/azure-container-networking/cns/hnsclient"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/requestcontroller"
"github.com/Azure/azure-container-networking/cns/requestcontroller/kubecontroller"
"github.com/Azure/azure-container-networking/cns/restserver"
acn "github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
Expand Down Expand Up @@ -323,6 +325,8 @@ func main() {
privateEndpoint = cnsconfig.ManagedSettings.PrivateEndpoint
infravnet = cnsconfig.ManagedSettings.InfrastructureNetworkID
nodeID = cnsconfig.ManagedSettings.NodeID
} else if cnsconfig.ChannelMode == cns.CRD {
config.ChannelMode = cns.CRD
} else if acn.GetArg(acn.OptManaged).(bool) {
config.ChannelMode = cns.Managed
}
Expand Down Expand Up @@ -423,6 +427,46 @@ func main() {
httpRestService.SyncNodeStatus(ep, vnet, node, json.RawMessage{})
}
}(privateEndpoint, infravnet, nodeID)
} else if config.ChannelMode == cns.CRD {
var requestController requestcontroller.RequestController

logger.Printf("[Azure CNS] Starting request controller")

kubeConfig, err := kubecontroller.GetKubeConfig()
if err != nil {
logger.Errorf("[Azure CNS] Failed to get kubeconfig for request controller: %v", err)
return
}

//convert interface type to implementation type
httpRestServiceImplementation, ok := httpRestService.(*restserver.HTTPRestService)
if !ok {
logger.Errorf("[Azure CNS] Failed to convert interface httpRestService to implementation: %v", httpRestService)
return
}

// Set orchestrator type
orchestrator := cns.SetOrchestratorTypeRequest{
OrchestratorType: cns.KubernetesCRD,
}
httpRestServiceImplementation.SetNodeOrchestrator(&orchestrator)

// Get crd implementation of request controller
requestController, err = kubecontroller.NewCrdRequestController(httpRestServiceImplementation, kubeConfig)
if err != nil {
logger.Errorf("[Azure CNS] Failed to make crd request controller :%v", err)
return
}

//Start the RequestController which starts the reconcile loop
requestControllerStopChannel := make(chan struct{})
defer close(requestControllerStopChannel)
go func() {
if err := requestController.StartRequestController(requestControllerStopChannel); err != nil {
logger.Errorf("[Azure CNS] Failed to start request controller: %v", err)
return
}
}()
}

var netPlugin network.NetPlugin
Expand Down