Reconciler: Reconcile dodo Apps as well

Fix service-account assignment.

Change-Id: Ic66c46ae5b728e09ee9118f61e31ab860623bce0
diff --git a/core/fluxcd-reconciler/Makefile b/core/fluxcd-reconciler/Makefile
index 70f5889..0ef3b6c 100644
--- a/core/fluxcd-reconciler/Makefile
+++ b/core/fluxcd-reconciler/Makefile
@@ -1,3 +1,9 @@
+repo_name ?= giolekva
+podman ?= docker
+ifeq ($($(podman)), $(podman))
+manifest_dest=docker://docker.io/$(repo_name)/fluxcd-reconciler:latest
+endif
+
 clean:
 	rm -rf tmp
 	rm -f fluxcd_reconciler fluxcd_reconciler_*
@@ -27,18 +33,18 @@
 push_arm64: clean build_arm64
 	mkdir tmp
 	cp -r ../../charts tmp/
-	podman build --platform linux/arm64 --tag=giolekva/fluxcd-reconciler:arm64 .
+	$(podman) build --platform linux/arm64 --tag=$(repo_name)/fluxcd-reconciler:arm64 .
 	rm -rf tmp
-	podman push giolekva/fluxcd-reconciler:arm64
+	$(podman) push $(repo_name)/fluxcd-reconciler:arm64
 
 push_amd64: clean build_amd64
 	mkdir tmp
 	cp -r ../../charts tmp/
-	podman build --platform linux/amd64 --tag=giolekva/fluxcd-reconciler:amd64 .
+	$(podman) build --platform linux/amd64 --tag=$(repo_name)/fluxcd-reconciler:amd64 .
 	rm -rf tmp
-	podman push giolekva/fluxcd-reconciler:amd64
+	$(podman) push $(repo_name)/fluxcd-reconciler:amd64
 
 push: push_arm64 push_amd64
-	podman manifest create giolekva/fluxcd-reconciler:latest giolekva/fluxcd-reconciler:arm64 giolekva/fluxcd-reconciler:amd64
-	podman manifest push giolekva/fluxcd-reconciler:latest docker://docker.io/giolekva/fluxcd-reconciler:latest
-	podman manifest rm giolekva/fluxcd-reconciler:latest
+	$(podman) manifest create $(repo_name)/fluxcd-reconciler:latest $(repo_name)/fluxcd-reconciler:arm64 $(repo_name)/fluxcd-reconciler:amd64
+	$(podman) manifest push $(repo_name)/fluxcd-reconciler:latest $(manifest_dest)
+	$(podman) manifest rm $(repo_name)/fluxcd-reconciler:latest
diff --git a/core/fluxcd-reconciler/main.go b/core/fluxcd-reconciler/main.go
index 9220fec..c308b82 100644
--- a/core/fluxcd-reconciler/main.go
+++ b/core/fluxcd-reconciler/main.go
@@ -66,13 +66,19 @@
 	namespace string,
 	name string,
 ) error {
+	fmt.Printf("%+v %s %s\n", res, namespace, name)
 	unstr, err := client.Resource(res).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
 	if err != nil {
 		return err
 	}
 	timeNowTime := time.Now()
 	annotations := unstr.GetAnnotations()
+	if annotations == nil {
+		annotations = map[string]string{}
+		unstr.SetAnnotations(annotations)
+	}
 	annotations[reconcileAnnotation] = timeNowTime.Format(reconcileAtLayout)
+	fmt.Printf("New reconciled at: %+v\n", annotations[reconcileAnnotation])
 	unstr.SetAnnotations(annotations)
 	unstr, err = client.Resource(res).Namespace(namespace).Update(context.TODO(), unstr, metav1.UpdateOptions{})
 	if err != nil {
@@ -85,14 +91,14 @@
 		}
 		reconciledAt, err := getReconciledAt(unstr)
 		if err != nil {
-			return err
+			continue
 		}
 		reconciledAtTime, err := time.Parse(reconcileAtLayout, reconciledAt)
 		if err != nil {
 			return err
 		}
-		reconciledAtTime = reconciledAtTime.Add(3 * time.Hour)
-		if reconciledAtTime.After(timeNowTime) {
+		fmt.Printf("Current reconciled at: %s\n", reconciledAtTime.Format(reconcileAtLayout))
+		if reconciledAtTime.Equal(timeNowTime) || reconciledAtTime.After(timeNowTime) {
 			return nil
 		}
 	}
@@ -116,7 +122,8 @@
 		Resource: "gitrepositories",
 	}
 	if err := reconcile(s.client, res, namespace, name); err != nil {
-		http.Error(w, "error", http.StatusInternalServerError)
+		fmt.Println(err)
+		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
 }
@@ -139,7 +146,8 @@
 		Resource: "kustomizations",
 	}
 	if err := reconcile(s.client, res, namespace, name); err != nil {
-		http.Error(w, "error", http.StatusInternalServerError)
+		fmt.Println(err)
+		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
 }