fixup! fixup! fixup! fixup! fixup! General improvements

This commit is contained in:
2025-01-10 12:41:22 +00:00
parent a7273d688f
commit cfaa6918a7
4 changed files with 42 additions and 6 deletions
+2 -2
View File
@@ -10,9 +10,9 @@ description: |
type: application type: application
version: 0.2.29 version: 0.2.30
appVersion: "0.2.29" appVersion: "0.2.30"
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
+1 -1
View File
@@ -12,7 +12,7 @@ sa:
- ALL - ALL
image: image:
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
tag: 0.2.29 tag: 0.2.30
resources: resources:
limits: limits:
cpu: 500m cpu: 500m
+24 -2
View File
@@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"flag" "flag"
"os" "os"
@@ -25,7 +26,9 @@ import (
// to ensure that exec-entrypoint and run can make use of them. // to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme" clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
@@ -150,10 +153,29 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if err = (&raczylocomcontroller.ClusterImageExportReconciler{ // Get controller pod annotations
ctx := context.Background()
podName := os.Getenv("POD_NAME")
podNamespace := os.Getenv("POD_NAMESPACE")
var podAnnotations map[string]string
if podName != "" && podNamespace != "" {
pod := &corev1.Pod{}
if err := mgr.GetAPIReader().Get(ctx, types.NamespacedName{
Name: podName,
Namespace: podNamespace,
}, pod); err == nil {
podAnnotations = pod.Annotations
} else {
setupLog.Error(err, "unable to get controller pod annotations")
}
}
exportController := &raczylocomcontroller.ClusterImageExportReconciler{
Client: mgr.GetClient(), Client: mgr.GetClient(),
Scheme: mgr.GetScheme(), Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil { }
exportController.InjectPodAnnotations(podAnnotations)
if err = exportController.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ClusterImageExport") setupLog.Error(err, "unable to create controller", "controller", "ClusterImageExport")
os.Exit(1) os.Exit(1)
} }
@@ -26,6 +26,11 @@ import (
type ClusterImageExportReconciler struct { type ClusterImageExportReconciler struct {
client.Client client.Client
Scheme *runtime.Scheme Scheme *runtime.Scheme
podAnnotations map[string]string
}
func (r *ClusterImageExportReconciler) InjectPodAnnotations(annotations map[string]string) {
r.podAnnotations = annotations
} }
// +kubebuilder:rbac:groups=raczylo.com,resources=*,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=raczylo.com,resources=*,verbs=get;list;watch;create;update;patch;delete
@@ -320,12 +325,21 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
backoffLimit := int32(2) // 3 total attempts (initial + 2 retries) backoffLimit := int32(2) // 3 total attempts (initial + 2 retries)
ttlSecondsAfterFinished := int32(30) // Delete job 30 seconds after completion ttlSecondsAfterFinished := int32(30) // Delete job 30 seconds after completion
// Merge controller pod annotations with job annotations
mergedAnnotations := make(map[string]string)
for k, v := range r.podAnnotations {
mergedAnnotations[k] = v
}
for k, v := range clusterImageExport.Spec.JobAnnotations {
mergedAnnotations[k] = v
}
jobParams := shared.JobParams{ jobParams := shared.JobParams{
Name: normalisedImageName, Name: normalisedImageName,
Namespace: clusterImageExport.Namespace, Namespace: clusterImageExport.Namespace,
Image: shared.BACKUP_JOB_IMAGE, Image: shared.BACKUP_JOB_IMAGE,
Commands: defaultCommands, Commands: defaultCommands,
Annotations: clusterImageExport.Spec.JobAnnotations, Annotations: mergedAnnotations,
ServiceAccount: "", ServiceAccount: "",
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets, ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
BackoffLimit: &backoffLimit, BackoffLimit: &backoffLimit,