Skip to content
Snippets Groups Projects
Commit 5fa17f28 authored by Alex de Cock Buning's avatar Alex de Cock Buning
Browse files

kubernetes api: added more loggers for a better debugging

parent 8c713a50
No related branches found
No related tags found
1 merge request!2repo: added new directory where utils scripts will be
...@@ -46,8 +46,6 @@ var ( ...@@ -46,8 +46,6 @@ var (
setupLog = ctrl.Log.WithName("setup") setupLog = ctrl.Log.WithName("setup")
) )
const SWITCHES_NAMESPACE = "default"
func init() { func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(clientgoscheme.AddToScheme(scheme))
...@@ -138,7 +136,7 @@ func main() { ...@@ -138,7 +136,7 @@ func main() {
if err = (&controller.PodReconciler{ if err = (&controller.PodReconciler{
Client: mgr.GetClient(), Client: mgr.GetClient(),
Scheme: mgr.GetScheme(), Scheme: mgr.GetScheme(),
SwitchesNamespace: SWITCHES_NAMESPACE, SwitchesNamespace: os.Getenv("SWITCHES_NAMESPACE"),
}).SetupWithManager(mgr); err != nil { }).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Pod") setupLog.Error(err, "unable to create controller", "controller", "Pod")
os.Exit(1) os.Exit(1)
...@@ -158,7 +156,7 @@ func main() { ...@@ -158,7 +156,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if os.Getenv("ENABLE_WEBHOOKS") != "false" { if os.Getenv("ENABLE_WEBHOOKS") != "false" {
podAnnotator := &controller.PodAnnotator{Client: mgr.GetClient(), SwitchesNamespace: SWITCHES_NAMESPACE} podAnnotator := &controller.PodAnnotator{Client: mgr.GetClient(), SwitchesNamespace: os.Getenv("SWITCHES_NAMESPACE")}
if err := podAnnotator.InjectDecoder(admission.NewDecoder(mgr.GetScheme())); err != nil { if err := podAnnotator.InjectDecoder(admission.NewDecoder(mgr.GetScheme())); err != nil {
setupLog.Error(err, "unable to inject decoder into PodAnnotator") setupLog.Error(err, "unable to inject decoder into PodAnnotator")
os.Exit(1) os.Exit(1)
......
...@@ -158,8 +158,10 @@ func (r *L2NetworkReconciler) SetupWithManager(mgr ctrl.Manager) error { ...@@ -158,8 +158,10 @@ func (r *L2NetworkReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Log.Info("this is the controller ip", os.Getenv("CONTROLLER_IP")) r.Log.Info("this is the controller ip", os.Getenv("CONTROLLER_IP"))
fmt.Println(os.Getenv("CONTROLLER_IP")) fmt.Println(os.Getenv("CONTROLLER_IP"))
fmt.Println(os.Getenv("CONTROLLER_PORT"))
// Initialize the InternalClient with the base URL of the SDN controller // Initialize the InternalClient with the base URL of the SDN controller
clientConfig := sdnclient.ClientConfig{BaseURL: fmt.Sprintf("http://%s:8181/onos", os.Getenv("CONTROLLER_IP")), Username: "karaf", Password: "karaf"} clientConfig := sdnclient.ClientConfig{BaseURL: fmt.Sprintf("http://%s:%s/onos", os.Getenv("CONTROLLER_IP"), os.Getenv("CONTROLLER_PORT")), Username: "karaf", Password: "karaf"}
r.InternalClient, err = sdnclient.NewClient(sdnclient.InternalType, clientConfig) r.InternalClient, err = sdnclient.NewClient(sdnclient.InternalType, clientConfig)
if err != nil { if err != nil {
......
...@@ -179,7 +179,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R ...@@ -179,7 +179,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
var err error var err error
// Initialize the InternalClient with the base URL of the SDN controller // Initialize the InternalClient with the base URL of the SDN controller
clientConfig := sdnclient.ClientConfig{BaseURL: fmt.Sprintf("http://%s:8181/onos", os.Getenv("CONTROLLER_IP")), Username: "karaf", Password: "karaf"} clientConfig := sdnclient.ClientConfig{BaseURL: fmt.Sprintf("http://%s:%s/onos", os.Getenv("CONTROLLER_IP"), os.Getenv("CONTROLLER_PORT")), Username: "karaf", Password: "karaf"}
r.InternalClient, err = sdnclient.NewClient(sdnclient.InternalType, clientConfig) r.InternalClient, err = sdnclient.NewClient(sdnclient.InternalType, clientConfig)
if err != nil { if err != nil {
......
...@@ -41,6 +41,7 @@ type NetworkAnnotation struct { ...@@ -41,6 +41,7 @@ type NetworkAnnotation struct {
func (a *PodAnnotator) Handle(ctx context.Context, req admission.Request) admission.Response { func (a *PodAnnotator) Handle(ctx context.Context, req admission.Request) admission.Response {
log := log.FromContext(ctx) log := log.FromContext(ctx)
log.Info("Registering pod")
// First we decode the pod // First we decode the pod
pod := &corev1.Pod{} pod := &corev1.Pod{}
...@@ -87,8 +88,11 @@ func (a *PodAnnotator) Handle(ctx context.Context, req admission.Request) admiss ...@@ -87,8 +88,11 @@ func (a *PodAnnotator) Handle(ctx context.Context, req admission.Request) admiss
netAttachDef := &netAttachDefs.Items[index] netAttachDef := &netAttachDefs.Items[index]
newAnnotation := NetworkAnnotation{Name: netAttachDef.Name, IPAdresses: network.IPAdresses} newAnnotation := NetworkAnnotation{Name: netAttachDef.Name, IPAdresses: network.IPAdresses}
netAttachDef.Labels[netAttachDefLabel] = "true" netAttachDef.Labels[netAttachDefLabel] = "true"
log.Info(fmt.Sprintf("updating network attachment definition_ ", netAttachDef))
err = a.Client.Update(ctx, netAttachDef) err = a.Client.Update(ctx, netAttachDef)
if err != nil { if err != nil {
log.Error(err, "Could not update network attachment definition")
} }
multusAnnotations = append(multusAnnotations, newAnnotation) multusAnnotations = append(multusAnnotations, newAnnotation)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment