diff --git a/README.md b/README.md index 8e34142..d57f385 100644 --- a/README.md +++ b/README.md @@ -138,5 +138,5 @@ delete vino CR and make sure DaemonSet is deleted as well ## Get in Touch For any questions on the ViNo, or other Airship projects, we encourage you to join the community on -Slack/IRC or by participating in the mailing list. Please see this [Wiki](https://wiki.openstack.org/wiki/Airship#Get_in_Touch) for +Slack/IRC or by participating in the mailing list. Please see this [Wiki](https://wiki.openstack.org/wiki/Airship#Get_in_Touch) for contact information, and the community meeting schedules. \ No newline at end of file diff --git a/controllers/vino_controller.go b/controllers/vino_controller.go index 9c4aa9d..5d40911 100644 --- a/controllers/vino_controller.go +++ b/controllers/vino_controller.go @@ -112,7 +112,7 @@ func (r *VinoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. } vino.Status.ConfigMapReady = true - err = r.ensureDaemonSet(ctx, req.NamespacedName, vino) + err = r.ensureDaemonSet(ctx, vino) if err != nil { err = fmt.Errorf("Could not reconcile Daemonset: %w", err) readyCondition := metav1.Condition{ @@ -134,7 +134,6 @@ func (r *VinoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. } func (r *VinoReconciler) ensureConfigMap(ctx context.Context, name types.NamespacedName, vino *vinov1.Vino) error { - logger := r.Log.WithValues("vino", name) generatedCM, err := r.buildConfigMap(name, vino) @@ -225,8 +224,7 @@ func needsUpdate(generated, current *corev1.ConfigMap) bool { return false } -func (r *VinoReconciler) ensureDaemonSet(ctx context.Context, name types.NamespacedName, vino *vinov1.Vino) error { - +func (r *VinoReconciler) ensureDaemonSet(ctx context.Context, vino *vinov1.Vino) error { ds, err := r.overrideDaemonSet(ctx, vino) if err != nil { return err @@ -238,7 +236,11 @@ func (r *VinoReconciler) ensureDaemonSet(ctx context.Context, name types.Namespa r.decorateDaemonSet(ds, vino) - if err := applyRuntimeObject(ctx, types.NamespacedName{Name: ds.Name, Namespace: ds.Namespace}, ds, r.Client); err != nil { + if err := applyRuntimeObject( + ctx, + types.NamespacedName{Name: ds.Name, Namespace: ds.Namespace}, + ds, + r.Client); err != nil { return err } @@ -288,12 +290,13 @@ func (r *VinoReconciler) decorateDaemonSet(ds *appsv1.DaemonSet, vino *vinov1.Vi "vino instance", vino.Namespace+"/"+vino.Name, "container name", c.Name, ) - ds.Spec.Template.Spec.Containers[i].VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{ - MountPath: "/vino/spec", - Name: volume, - ReadOnly: true, - SubPath: ConfigMapKeyVinoSpec, - }) + ds.Spec.Template.Spec.Containers[i].VolumeMounts = append( + ds.Spec.Template.Spec.Containers[i].VolumeMounts, corev1.VolumeMount{ + MountPath: "/vino/spec", + Name: volume, + ReadOnly: true, + SubPath: ConfigMapKeyVinoSpec, + }) } } } @@ -377,10 +380,20 @@ func (r *VinoReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *VinoReconciler) finalize(ctx context.Context, vino *vinov1.Vino) error { // TODO aggregate errors instead - if err := r.Delete(ctx, &appsv1.DaemonSet{ObjectMeta: metav1.ObjectMeta{Name: vino.Name, Namespace: vino.Namespace}}); err != nil { + if err := r.Delete(ctx, + &appsv1.DaemonSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: vino.Name, Namespace: vino.Namespace, + }, + }); err != nil { return err } - if err := r.Delete(ctx, &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: vino.Name, Namespace: vino.Namespace}}); err != nil { + if err := r.Delete(ctx, + &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: vino.Name, Namespace: vino.Namespace, + }, + }); err != nil { return err } controllerutil.RemoveFinalizer(vino, vinov1.VinoFinalizer) @@ -396,7 +409,7 @@ func defaultDaemonSet(vino *vinov1.Vino) (ds *appsv1.DaemonSet) { biDirectional := corev1.MountPropagationBidirectional - ds = &appsv1.DaemonSet{ + return &appsv1.DaemonSet{ ObjectMeta: metav1.ObjectMeta{ Name: vino.Name, Namespace: vino.Namespace, @@ -522,7 +535,6 @@ func defaultDaemonSet(vino *vinov1.Vino) (ds *appsv1.DaemonSet) { }, }, } - return } func applyRuntimeObject(ctx context.Context, key client.ObjectKey, obj client.Object, c client.Client) error { diff --git a/nodelabeler/main.go b/nodelabeler/main.go index 5ea2b8b..4bac9de 100644 --- a/nodelabeler/main.go +++ b/nodelabeler/main.go @@ -15,6 +15,7 @@ limitations under the License. package main import ( + "context" "encoding/json" "net" "os" @@ -32,7 +33,10 @@ import ( ) func main() { - logger, _ := zap.NewProduction() + logger, err := zap.NewProduction() + if err != nil { + log.Fatal(err.Error()) + } log := logger.Named("nodelabeler") nodeName, ok := os.LookupEnv("NODE") @@ -67,16 +71,17 @@ func main() { } ifaceAddr := strings.Split(addrs[0].String(), "/")[0] labels := map[string]string{ - "airshipit.org/vino.nodebridgegw": ifaceAddr, + "airshipit.org/vino.nodebridgegw": ifaceAddr, } + ctx := context.Background() - node, err := clientset.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{}) + node, err := clientset.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{}) if err != nil { log.Fatal(err.Error()) } for label, value := range labels { - err = addLabelToNode(clientset, node, label, value) + err = addLabelToNode(ctx, clientset, node, label, value) if err != nil { log.Fatal(err.Error()) } @@ -86,7 +91,11 @@ func main() { } } -func addLabelToNode(clientset *kubernetes.Clientset, node *v1.Node, key string, value string) error { +func addLabelToNode( + ctx context.Context, + clientset *kubernetes.Clientset, + node *v1.Node, + key, value string) error { log.Info("Applying node label", zap.String(key, value), ) @@ -113,7 +122,7 @@ func addLabelToNode(clientset *kubernetes.Clientset, node *v1.Node, key string, zap.String("patch", string(patch)), ) - _, err = clientset.CoreV1().Nodes().Patch(node.Name, types.MergePatchType, patch) + _, err = clientset.CoreV1().Nodes().Patch(ctx, node.Name, types.MergePatchType, patch, metav1.PatchOptions{}) if err != nil { return err }