Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
3426829
cns ipam
matmerr Jun 17, 2020
0f5dc91
cnsclient requestipaddress in cni
matmerr Jun 18, 2020
69a5c34
cnsclient release
matmerr Jun 18, 2020
f90fea2
state update, tbd
matmerr Jun 19, 2020
3b3649b
add windows specific vendor
matmerr Jun 19, 2020
e8d0ce3
update windows e2e's
matmerr Jun 20, 2020
b8f10f6
further refactoring
matmerr Jun 24, 2020
638c4ac
cnsclient integration tests
matmerr Jun 25, 2020
20c51fd
cns release integration test
matmerr Jun 25, 2020
c982f4c
fix nested lock
matmerr Jun 25, 2020
a475c7c
Merge remote-tracking branch 'upstream/master' into cnsipamcni
matmerr Jun 25, 2020
c0c47ba
Simply issue template
Jun 10, 2020
c766a57
Use issue template builder
Jun 17, 2020
069c596
Small improvements
Jun 17, 2020
931abab
template revision
matmerr Jun 25, 2020
da39b2a
Merge pull request #13 from matmerr/githubtemplates
matmerr Jun 25, 2020
0c7f746
move cnsclient to ipamdelegate calls
matmerr Jun 29, 2020
33ef3f8
remove cni changes
matmerr Jun 29, 2020
1a10ffa
addressed feedback
matmerr Jul 1, 2020
0b46c1f
add pending release state
matmerr Jul 1, 2020
fb29655
First iteration of PopulateIP
pjohnst5 Jul 7, 2020
63b58d6
Renaming apiclientinterface.go to kubeclientinterface.go
pjohnst5 Jul 7, 2020
21b2ae0
address feedback
matmerr Jul 8, 2020
5519348
Adding parameter validation to build scripts (#246)
PatrickLang Jun 25, 2020
d3f9839
Update Github Templates (#592)
matmerr Jun 26, 2020
a22f0cc
Improving and adding CNI unit tests (#543)
DancingLinks Jun 26, 2020
82a16e3
Request controller for CNS (#583)
pjohnst5 Jul 2, 2020
57d55c3
First iteration of PopulateIP
pjohnst5 Jul 7, 2020
74911bb
Renaming apiclientinterface.go to kubeclientinterface.go
pjohnst5 Jul 7, 2020
722e336
fixed merge conflicts
pjohnst5 Jul 9, 2020
1e511e9
fixed main
pjohnst5 Jul 9, 2020
0f6b366
Renamed apiclientinterface.go kubeclientinterface.go
pjohnst5 Jul 9, 2020
ac4d732
Merge branch 'reconcile-on-start' of github.com:pjohnst5/azure-contai…
pjohnst5 Jul 9, 2020
425f512
removed line from go.sum to leave go.sum untouched in the long run
pjohnst5 Jul 9, 2020
35bda47
fix tests
matmerr Jul 9, 2020
4ec459c
update comments
matmerr Jul 9, 2020
125485f
ipam refactor with clearer locking
matmerr Jul 9, 2020
1b42027
fix nits
matmerr Jul 10, 2020
c8bd6c4
Merge branch 'master' into cnsipamcni
matmerr Jul 10, 2020
0f3863e
Merge remote-tracking branch 'upstream/master' into cnsipamcni
matmerr Jul 10, 2020
af41c5a
Merge branch 'master' into cnsipamcni
matmerr Jul 10, 2020
de0692c
Finished reconcile on reboot and unit tests
pjohnst5 Jul 10, 2020
f9fc839
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 10, 2020
772c5bf
Merge branch 'cnsipamcni' of github.com:matmerr/azure-container-netwo…
pjohnst5 Jul 10, 2020
dbcb17c
add separate structs for new apis
matmerr Jul 10, 2020
e2622e8
update tests based on feedback
matmerr Jul 13, 2020
a3d5c26
Merge branch 'cnsipamcni' into reconcile-on-start
pjohnst5 Jul 13, 2020
69ad3aa
remove nested lock on fail and address comments
matmerr Jul 13, 2020
61fa082
address feedback and add validation
matmerr Jul 13, 2020
1fd805c
update test
matmerr Jul 13, 2020
9e5058d
Finished upadate and init cns state
pjohnst5 Jul 13, 2020
f40264e
Merge branch 'cnsipamcni' into reconcile-on-start
pjohnst5 Jul 13, 2020
e965d7d
rename api's for allocation, nits, readlock for get api's
matmerr Jul 13, 2020
2b7cb14
changed back to ncrequest as well
pjohnst5 Jul 13, 2020
fe791f8
make release idempotent, and add tests
matmerr Jul 13, 2020
0717310
Merged
pjohnst5 Jul 13, 2020
074c772
removed merge conflict
pjohnst5 Jul 13, 2020
b12091a
ReadyToIPAM bool back in service
pjohnst5 Jul 13, 2020
0556409
update getNetworkContainerResponse to take RLock
matmerr Jul 13, 2020
16700bf
Removed ncrequest, not needed for cns, only nc id is needed
pjohnst5 Jul 13, 2020
533f46d
Merge branch 'cnsipamcni' into reconcile-on-start
pjohnst5 Jul 13, 2020
e12c08a
added error check
pjohnst5 Jul 14, 2020
476b76c
marking unused ips as available before passing to cns
pjohnst5 Jul 14, 2020
8d6346b
Added ncid to unit tests
pjohnst5 Jul 14, 2020
188af9d
Added one more check in unit test
pjohnst5 Jul 14, 2020
0e5424b
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 14, 2020
2c93a5b
Added cns to spec parameter
pjohnst5 Jul 14, 2020
04f1b4d
Made changes to example main.go for translation usage
pjohnst5 Jul 14, 2020
e043fdd
Addressed Ramiro's comments
pjohnst5 Jul 15, 2020
956b036
Adding api template and skeleton to unblock Neha
pjohnst5 Jul 15, 2020
1995f10
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 15, 2020
a3dfbc6
Merge branch 'api-template' into reconcile-on-start
pjohnst5 Jul 15, 2020
a884dd2
Fixed merge conflict
pjohnst5 Jul 15, 2020
f81e82b
Removed new container type and reversed api order
pjohnst5 Jul 15, 2020
adbdea0
Fixed tests and reconcile call
pjohnst5 Jul 15, 2020
6188700
Merge branch 'api-template' into reconcile-on-start
pjohnst5 Jul 15, 2020
47340b4
removing unnecessary changes
pjohnst5 Jul 15, 2020
c7f12a9
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 15, 2020
110520c
Added init before reconcile loop, need to add tests still
pjohnst5 Jul 16, 2020
413c3dc
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 16, 2020
f47bd27
Stubbed out tests
pjohnst5 Jul 16, 2020
b55199e
Finished unit tests for initializing cns state before reconcile loop
pjohnst5 Jul 17, 2020
5e2894b
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 17, 2020
71d77cf
Merge branch 'master' into reconcile-on-start
pjohnst5 Jul 17, 2020
ae5cfd7
Cleaned up an error check
pjohnst5 Jul 17, 2020
8999d35
Cleaned up one more err check
pjohnst5 Jul 17, 2020
f930756
working on cri
pjohnst5 Jul 20, 2020
5a4ec4c
loop until crd is installed"
pjohnst5 Jul 21, 2020
11b7607
Added check if crd is not defined in cluster, exits with 1
pjohnst5 Jul 21, 2020
e335031
fixed comment
pjohnst5 Jul 21, 2020
3ffcf68
Changed init to internal api
pjohnst5 Jul 21, 2020
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
18 changes: 0 additions & 18 deletions cns/requestcontroller/kubecontroller/apiclientinterface.go

This file was deleted.

193 changes: 180 additions & 13 deletions cns/requestcontroller/kubecontroller/crdrequestcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ package kubecontroller
import (
"context"
"errors"
"fmt"
"os"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/cnsclient"
"github.com/Azure/azure-container-networking/cns/cnsclient/httpapi"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand All @@ -17,18 +23,25 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

const nodeNameEnvVar = "NODENAME"
const k8sNamespace = "kube-system"
const prometheusAddress = "0" //0 means disabled
const (
nodeNameEnvVar = "NODENAME"
k8sNamespace = "kube-system"
crdTypeName = "nodenetworkconfigs"
allNamespaces = ""
prometheusAddress = "0" //0 means disabled
)

// crdRequestController
// - watches CRD status changes
// - updates CRD spec
type crdRequestController struct {
mgr manager.Manager //Manager starts the reconcile loop which watches for crd status changes
KubeClient KubeClient //KubeClient interacts with API server
nodeName string //name of node running this program
Reconciler *CrdReconciler
mgr manager.Manager //Manager starts the reconcile loop which watches for crd status changes
KubeClient KubeClient //KubeClient is a cached client which interacts with API server
directAPIClient DirectAPIClient //Direct client to interact with API server
directCRDClient DirectCRDClient //Direct client to interact with CRDs on API server
CNSClient cnsclient.APIClient
nodeName string //name of node running this program
Reconciler *CrdReconciler
}

// GetKubeConfig precedence
Expand Down Expand Up @@ -69,6 +82,18 @@ func NewCrdRequestController(restService *restserver.HTTPRestService, kubeconfig
return nil, errors.New("Error adding NodeNetworkConfig scheme to runtime scheme")
}

// Create a direct client to the API server which we use to list pods when initializing cns state before reconcile loop
directAPIClient, err := NewAPIDirectClient(kubeconfig)
if err != nil {
return nil, fmt.Errorf("Error creating direct API Client: %v", err)
}

// Create a direct client to the API server configured to get nodenetconfigs to get nnc for same reason above
directCRDClient, err := NewCRDDirectClient(kubeconfig, &nnc.GroupVersion)
if err != nil {
return nil, fmt.Errorf("Error creating direct CRD client: %v", err)
}

// Create manager for CrdRequestController
// MetricsBindAddress is the tcp address that the controller should bind to
// for serving prometheus metrics, set to "0" to disable
Expand Down Expand Up @@ -102,10 +127,13 @@ func NewCrdRequestController(restService *restserver.HTTPRestService, kubeconfig

// Create the requestController
crdRequestController := crdRequestController{
mgr: mgr,
KubeClient: mgr.GetClient(),
nodeName: nodeName,
Reconciler: crdreconciler,
mgr: mgr,
KubeClient: mgr.GetClient(),
directAPIClient: directAPIClient,
directCRDClient: directCRDClient,
CNSClient: httpClient,
nodeName: nodeName,
Reconciler: crdreconciler,
}

return &crdRequestController, nil
Expand All @@ -115,14 +143,94 @@ func NewCrdRequestController(restService *restserver.HTTPRestService, kubeconfig
// Blocks until SIGINT or SIGTERM is received
// Notifies exitChan when kill signal received
func (crdRC *crdRequestController) StartRequestController(exitChan chan bool) error {
logger.Printf("Starting manager")
var (
err error
)

logger.Printf("Initializing CNS state")
if err = crdRC.initCNS(); err != nil {
logger.Errorf("[cns-rc] Error initializing cns state: %v", err)
return err
}

logger.Printf("Starting reconcile loop")
if err := crdRC.mgr.Start(SetupSignalHandler(exitChan)); err != nil {
logger.Errorf("[cns-rc] Error starting manager: %v", err)
if crdRC.isNotDefined(err) {
logger.Errorf("[cns-rc] CRD is not defined on cluster, starting reconcile loop failed: %v", err)
os.Exit(1)
}

return err
}

return nil
}

// InitCNS initializes cns by passing pods and a createnetworkcontainerrequest
func (crdRC *crdRequestController) initCNS() error {
var (
pods *corev1.PodList
pod corev1.Pod
podInfo *cns.KubernetesPodInfo
nodeNetConfig *nnc.NodeNetworkConfig
podInfoByIP map[string]*cns.KubernetesPodInfo
cntxt context.Context
ncRequest *cns.CreateNetworkContainerRequest
err error
)

cntxt = context.Background()

// Get nodeNetConfig using direct client
if nodeNetConfig, err = crdRC.getNodeNetConfigDirect(cntxt, crdRC.nodeName, k8sNamespace); err != nil {
// If the CRD is not defined, exit
if crdRC.isNotDefined(err) {
logger.Errorf("CRD is not defined on cluster: %v", err)
os.Exit(1)
}

// If instance of crd is not found, ignore
// otherwise, log error and return
if client.IgnoreNotFound(err) != nil {
logger.Errorf("Error when getting nodeNetConfig using direct client when initializing cns state: %v", err)
return err
}
}

// Convert to CreateNetworkContainerRequest if crd not nill and is populated
if nodeNetConfig != nil && len(nodeNetConfig.Status.NetworkContainers) != 0 {
if ncRequest, err = CRDStatusToNCRequest(&nodeNetConfig.Status); err != nil {
logger.Errorf("Error when converting nodeNetConfig status into CreateNetworkContainerRequest: %v", err)
return err
}
}

// Get all pods using direct client
if pods, err = crdRC.getAllPods(cntxt, crdRC.nodeName); err != nil {
logger.Errorf("Error when getting all pods when initializing cns: %v", err)
return err
}

// Convert pod list to map of pod ip -> kubernetes pod info
if len(pods.Items) != 0 {
podInfoByIP = make(map[string]*cns.KubernetesPodInfo)
for _, pod = range pods.Items {
//Only add pods that aren't on the host network
if !pod.Spec.HostNetwork {
podInfo = &cns.KubernetesPodInfo{
PodName: pod.Name,
PodNamespace: pod.Namespace,
}
podInfoByIP[pod.Status.PodIP] = podInfo
}
}
}

// Call cnsclient init cns passing those two things
return crdRC.CNSClient.InitCNSState(ncRequest, podInfoByIP)

}

// UpdateCRDSpec updates the CRD spec
func (crdRC *crdRequestController) UpdateCRDSpec(cntxt context.Context, crdSpec *nnc.NodeNetworkConfigSpec) error {
nodeNetworkConfig, err := crdRC.getNodeNetConfig(cntxt, crdRC.nodeName, k8sNamespace)
Expand Down Expand Up @@ -159,6 +267,20 @@ func (crdRC *crdRequestController) getNodeNetConfig(cntxt context.Context, name,
return nodeNetworkConfig, nil
}

// getNodeNetConfigDirect gets the nodeNetworkConfig CRD using a direct client
func (crdRC *crdRequestController) getNodeNetConfigDirect(cntxt context.Context, name, namespace string) (*nnc.NodeNetworkConfig, error) {
var (
nodeNetworkConfig *nnc.NodeNetworkConfig
err error
)

if nodeNetworkConfig, err = crdRC.directCRDClient.Get(cntxt, name, namespace, crdTypeName); err != nil {
return nil, err
}

return nodeNetworkConfig, nil
}

// updateNodeNetConfig updates the nodeNetConfig object in the API server with the given nodeNetworkConfig object
func (crdRC *crdRequestController) updateNodeNetConfig(cntxt context.Context, nodeNetworkConfig *nnc.NodeNetworkConfig) error {
if err := crdRC.KubeClient.Update(cntxt, nodeNetworkConfig); err != nil {
Expand All @@ -167,3 +289,48 @@ func (crdRC *crdRequestController) updateNodeNetConfig(cntxt context.Context, no

return nil
}

// getAllPods gets all pods running on the node using the direct API client
func (crdRC *crdRequestController) getAllPods(cntxt context.Context, node string) (*corev1.PodList, error) {
var (
pods *corev1.PodList
err error
)

if pods, err = crdRC.directAPIClient.ListPods(cntxt, allNamespaces, node); err != nil {
return nil, err
}

return pods, nil
}

// isNotDefined tells whether the given error is a CRD not defined error
func (crdRC *crdRequestController) isNotDefined(err error) bool {
var (
statusError *apierrors.StatusError
ok bool
notDefined bool
cause metav1.StatusCause
)

if err == nil {
return false
}

if statusError, ok = err.(*apierrors.StatusError); !ok {
return false
}

if len(statusError.ErrStatus.Details.Causes) > 0 {
for _, cause = range statusError.ErrStatus.Details.Causes {
if cause.Type == metav1.CauseTypeUnexpectedServerResponse {
if apierrors.IsNotFound(err) {
notDefined = true
break
}
}
}
}

return notDefined
}
Loading