updates #3
| @@ -39,6 +39,30 @@ type ResourceDefaults struct { | ||||
| 	MemoryLimit string `json:"memoryLimit,omitempty"` | ||||
| } | ||||
|  | ||||
| // ImageUpdatePolicy defines the policy for automatic image updates. | ||||
| type ImageUpdatePolicy struct { | ||||
| 	// Enabled toggles the image update feature. | ||||
| 	// +optional | ||||
| 	Enabled bool `json:"enabled,omitempty"` | ||||
|  | ||||
| 	// CheckInterval specifies how often to check for image updates (e.g., "5m", "1h", "15m"). | ||||
| 	// Minimum interval recommended: 5m to avoid rate limiting. | ||||
| 	// +kubebuilder:validation:Pattern=`^([0-9]+(s|m|h))+$` | ||||
| 	// +kubebuilder:default="1h" | ||||
| 	// +optional | ||||
| 	CheckInterval string `json:"checkInterval,omitempty"` | ||||
|  | ||||
| 	// MonitoredTags is a list of keywords found in image tags that trigger update checks. | ||||
| 	// Example: ["latest", "master", "dev"] | ||||
| 	// +optional | ||||
| 	MonitoredTags []string `json:"monitoredTags,omitempty"` | ||||
|  | ||||
| 	// RestartAnnotation is the annotation key used to trigger deployment restarts. | ||||
| 	// If empty, a default will be used (e.g., "image-updater.my-operator.com/restartedAt"). | ||||
| 	// +optional | ||||
| 	RestartAnnotation string `json:"restartAnnotation,omitempty"` | ||||
| } | ||||
|  | ||||
| // NodeTainterConfigSpec defines the desired state of NodeTainterConfig. | ||||
| type NodeTainterConfigSpec struct { | ||||
| 	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||||
| @@ -68,6 +92,9 @@ type NodeTainterConfigSpec struct { | ||||
| 	// Example: "my-operator.example.com/skip-resource-defaults" | ||||
| 	// +optional | ||||
| 	OptOutLabelKey string `json:"optOutLabelKey,omitempty"` | ||||
|  | ||||
| 	// +optional | ||||
| 	ImageUpdatePolicy *ImageUpdatePolicy `json:"imageUpdatePolicy,omitempty"` | ||||
| } | ||||
|  | ||||
| // NodeTainterConfigStatus defines the observed state of NodeTainterConfig. | ||||
|   | ||||
| @@ -25,6 +25,26 @@ import ( | ||||
| 	runtime "k8s.io/apimachinery/pkg/runtime" | ||||
| ) | ||||
|  | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||||
| func (in *ImageUpdatePolicy) DeepCopyInto(out *ImageUpdatePolicy) { | ||||
| 	*out = *in | ||||
| 	if in.MonitoredTags != nil { | ||||
| 		in, out := &in.MonitoredTags, &out.MonitoredTags | ||||
| 		*out = make([]string, len(*in)) | ||||
| 		copy(*out, *in) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageUpdatePolicy. | ||||
| func (in *ImageUpdatePolicy) DeepCopy() *ImageUpdatePolicy { | ||||
| 	if in == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	out := new(ImageUpdatePolicy) | ||||
| 	in.DeepCopyInto(out) | ||||
| 	return out | ||||
| } | ||||
|  | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||||
| func (in *NodeTaintInfo) DeepCopyInto(out *NodeTaintInfo) { | ||||
| 	*out = *in | ||||
| @@ -119,6 +139,11 @@ func (in *NodeTainterConfigSpec) DeepCopyInto(out *NodeTainterConfigSpec) { | ||||
| 		*out = new(ResourceDefaults) | ||||
| 		**out = **in | ||||
| 	} | ||||
| 	if in.ImageUpdatePolicy != nil { | ||||
| 		in, out := &in.ImageUpdatePolicy, &out.ImageUpdatePolicy | ||||
| 		*out = new(ImageUpdatePolicy) | ||||
| 		(*in).DeepCopyInto(*out) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeTainterConfigSpec. | ||||
|   | ||||
| @@ -221,6 +221,15 @@ func main() { | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  | ||||
| 	if err = (&controller.ImageUpdateReconciler{ | ||||
| 		Client:   mgr.GetClient(), | ||||
| 		Scheme:   mgr.GetScheme(), | ||||
| 		Recorder: mgr.GetEventRecorderFor("imageupdate-controller"), | ||||
| 	}).SetupWithManager(mgr); err != nil { | ||||
| 		setupLog.Error(err, "unable to create controller", "controller", "ImageUpdate") | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  | ||||
| 	// +kubebuilder:scaffold:builder | ||||
|  | ||||
| 	if metricsCertWatcher != nil { | ||||
|   | ||||
| @@ -41,6 +41,33 @@ spec: | ||||
|           spec: | ||||
|             description: NodeTainterConfigSpec defines the desired state of NodeTainterConfig. | ||||
|             properties: | ||||
|               imageUpdatePolicy: | ||||
|                 description: ImageUpdatePolicy defines the policy for automatic image | ||||
|                   updates. | ||||
|                 properties: | ||||
|                   checkInterval: | ||||
|                     default: 1h | ||||
|                     description: |- | ||||
|                       CheckInterval specifies how often to check for image updates (e.g., "5m", "1h", "15m"). | ||||
|                       Minimum interval recommended: 5m to avoid rate limiting. | ||||
|                     pattern: ^([0-9]+(s|m|h))+$ | ||||
|                     type: string | ||||
|                   enabled: | ||||
|                     description: Enabled toggles the image update feature. | ||||
|                     type: boolean | ||||
|                   monitoredTags: | ||||
|                     description: |- | ||||
|                       MonitoredTags is a list of keywords found in image tags that trigger update checks. | ||||
|                       Example: ["latest", "master", "dev"] | ||||
|                     items: | ||||
|                       type: string | ||||
|                     type: array | ||||
|                   restartAnnotation: | ||||
|                     description: |- | ||||
|                       RestartAnnotation is the annotation key used to trigger deployment restarts. | ||||
|                       If empty, a default will be used (e.g., "image-updater.my-operator.com/restartedAt"). | ||||
|                     type: string | ||||
|                 type: object | ||||
|               labelRules: | ||||
|                 additionalProperties: | ||||
|                   type: string | ||||
|   | ||||
| @@ -21,6 +21,14 @@ rules: | ||||
|   - patch | ||||
|   - update | ||||
|   - watch | ||||
| - apiGroups: | ||||
|   - "" | ||||
|   resources: | ||||
|   - pods | ||||
|   verbs: | ||||
|   - get | ||||
|   - list | ||||
|   - watch | ||||
| - apiGroups: | ||||
|   - apps | ||||
|   resources: | ||||
|   | ||||
| @@ -16,3 +16,8 @@ spec: | ||||
|     cpuLimit: "500m" | ||||
|     memoryLimit: "512Mi" | ||||
|   optOutLabelKey: "andy.vendetti.ru/skip-resource-defaults" | ||||
|   imageUpdatePolicy: | ||||
|     enabled: true | ||||
|     checkInterval: "5m" | ||||
|     monitoredTags: ["latest", "dev"] | ||||
|     # restartAnnotation: "andy.vendetti.ru/restartedAt" | ||||
|   | ||||
							
								
								
									
										38
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								go.mod
									
									
									
									
									
								
							| @@ -20,7 +20,11 @@ require ( | ||||
| 	github.com/blang/semver/v4 v4.0.0 // indirect | ||||
| 	github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||||
| 	github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||||
| 	github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect | ||||
| 	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||||
| 	github.com/docker/cli v27.5.0+incompatible // indirect | ||||
| 	github.com/docker/distribution v2.8.3+incompatible // indirect | ||||
| 	github.com/docker/docker-credential-helpers v0.8.2 // indirect | ||||
| 	github.com/emicklei/go-restful/v3 v3.11.0 // indirect | ||||
| 	github.com/evanphx/json-patch/v5 v5.9.11 // indirect | ||||
| 	github.com/felixge/httpsnoop v1.0.4 // indirect | ||||
| @@ -39,6 +43,7 @@ require ( | ||||
| 	github.com/google/cel-go v0.22.0 // indirect | ||||
| 	github.com/google/gnostic-models v0.6.8 // indirect | ||||
| 	github.com/google/go-cmp v0.6.0 // indirect | ||||
| 	github.com/google/go-containerregistry v0.20.3 // indirect | ||||
| 	github.com/google/gofuzz v1.2.0 // indirect | ||||
| 	github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect | ||||
| 	github.com/google/uuid v1.6.0 // indirect | ||||
| @@ -46,43 +51,50 @@ require ( | ||||
| 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||||
| 	github.com/josharian/intern v1.0.0 // indirect | ||||
| 	github.com/json-iterator/go v1.1.12 // indirect | ||||
| 	github.com/klauspost/compress v1.17.11 // indirect | ||||
| 	github.com/mailru/easyjson v0.7.7 // indirect | ||||
| 	github.com/mitchellh/go-homedir v1.1.0 // indirect | ||||
| 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||||
| 	github.com/modern-go/reflect2 v1.0.2 // indirect | ||||
| 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||||
| 	github.com/opencontainers/go-digest v1.0.0 // indirect | ||||
| 	github.com/opencontainers/image-spec v1.1.0 // indirect | ||||
| 	github.com/pkg/errors v0.9.1 // indirect | ||||
| 	github.com/prometheus/client_golang v1.19.1 // indirect | ||||
| 	github.com/prometheus/client_model v0.6.1 // indirect | ||||
| 	github.com/prometheus/common v0.55.0 // indirect | ||||
| 	github.com/prometheus/procfs v0.15.1 // indirect | ||||
| 	github.com/sirupsen/logrus v1.9.3 // indirect | ||||
| 	github.com/spf13/cobra v1.8.1 // indirect | ||||
| 	github.com/spf13/pflag v1.0.5 // indirect | ||||
| 	github.com/stoewer/go-strcase v1.3.0 // indirect | ||||
| 	github.com/vbatts/tar-split v0.11.6 // indirect | ||||
| 	github.com/x448/float16 v0.8.4 // indirect | ||||
| 	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect | ||||
| 	go.opentelemetry.io/otel v1.28.0 // indirect | ||||
| 	go.opentelemetry.io/auto/sdk v1.1.0 // indirect | ||||
| 	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect | ||||
| 	go.opentelemetry.io/otel v1.33.0 // indirect | ||||
| 	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect | ||||
| 	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect | ||||
| 	go.opentelemetry.io/otel/metric v1.28.0 // indirect | ||||
| 	go.opentelemetry.io/otel/sdk v1.28.0 // indirect | ||||
| 	go.opentelemetry.io/otel/trace v1.28.0 // indirect | ||||
| 	go.opentelemetry.io/otel/metric v1.33.0 // indirect | ||||
| 	go.opentelemetry.io/otel/sdk v1.33.0 // indirect | ||||
| 	go.opentelemetry.io/otel/trace v1.33.0 // indirect | ||||
| 	go.opentelemetry.io/proto/otlp v1.3.1 // indirect | ||||
| 	go.uber.org/multierr v1.11.0 // indirect | ||||
| 	go.uber.org/zap v1.27.0 // indirect | ||||
| 	golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect | ||||
| 	golang.org/x/net v0.30.0 // indirect | ||||
| 	golang.org/x/oauth2 v0.23.0 // indirect | ||||
| 	golang.org/x/sync v0.8.0 // indirect | ||||
| 	golang.org/x/sys v0.26.0 // indirect | ||||
| 	golang.org/x/term v0.25.0 // indirect | ||||
| 	golang.org/x/text v0.19.0 // indirect | ||||
| 	golang.org/x/net v0.34.0 // indirect | ||||
| 	golang.org/x/oauth2 v0.25.0 // indirect | ||||
| 	golang.org/x/sync v0.10.0 // indirect | ||||
| 	golang.org/x/sys v0.29.0 // indirect | ||||
| 	golang.org/x/term v0.28.0 // indirect | ||||
| 	golang.org/x/text v0.21.0 // indirect | ||||
| 	golang.org/x/time v0.7.0 // indirect | ||||
| 	golang.org/x/tools v0.26.0 // indirect | ||||
| 	golang.org/x/tools v0.29.0 // indirect | ||||
| 	gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect | ||||
| 	google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect | ||||
| 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect | ||||
| 	google.golang.org/grpc v1.65.0 // indirect | ||||
| 	google.golang.org/protobuf v1.35.1 // indirect | ||||
| 	google.golang.org/protobuf v1.36.3 // indirect | ||||
| 	gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect | ||||
| 	gopkg.in/inf.v0 v0.9.1 // indirect | ||||
| 	gopkg.in/yaml.v3 v3.0.1 // indirect | ||||
|   | ||||
							
								
								
									
										51
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								go.sum
									
									
									
									
									
								
							| @@ -12,12 +12,20 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3 | ||||
| github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= | ||||
| github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= | ||||
| github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= | ||||
| github.com/containerd/stargz-snapshotter/estargz v0.16.3 h1:7evrXtoh1mSbGj/pfRccTampEyKpjpOnS3CyiV1Ebr8= | ||||
| github.com/containerd/stargz-snapshotter/estargz v0.16.3/go.mod h1:uyr4BfYfOj3G9WBVE8cOlQmXAbPN9VEQpBBeJIuOipU= | ||||
| github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||||
| github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= | ||||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/docker/cli v27.5.0+incompatible h1:aMphQkcGtpHixwwhAXJT1rrK/detk2JIvDaFkLctbGM= | ||||
| github.com/docker/cli v27.5.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= | ||||
| github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= | ||||
| github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= | ||||
| github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo= | ||||
| github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M= | ||||
| github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= | ||||
| github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= | ||||
| github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= | ||||
| @@ -60,6 +68,8 @@ github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYu | ||||
| github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||
| github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||||
| github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||
| github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI= | ||||
| github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI= | ||||
| github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | ||||
| github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= | ||||
| github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | ||||
| @@ -77,6 +87,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr | ||||
| github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= | ||||
| github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= | ||||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||||
| github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= | ||||
| github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= | ||||
| github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= | ||||
| github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= | ||||
| github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= | ||||
| @@ -86,6 +98,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||||
| github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||||
| github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= | ||||
| github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= | ||||
| github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||||
| github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||||
| github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||
| github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= | ||||
| github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||
| @@ -97,6 +111,10 @@ github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg | ||||
| github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= | ||||
| github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw= | ||||
| github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= | ||||
| github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= | ||||
| github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= | ||||
| github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= | ||||
| github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= | ||||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| @@ -113,6 +131,8 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG | ||||
| github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= | ||||
| github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= | ||||
| github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||||
| github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= | ||||
| github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||||
| github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= | ||||
| github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= | ||||
| github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||||
| @@ -123,29 +143,44 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ | ||||
| github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||||
| github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||
| github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||||
| github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||||
| github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||||
| github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||
| github.com/vbatts/tar-split v0.11.6 h1:4SjTW5+PU11n6fZenf2IPoV8/tz3AaYHMWjf23envGs= | ||||
| github.com/vbatts/tar-split v0.11.6/go.mod h1:dqKNtesIOr2j2Qv3W/cHjnvk9I8+G7oAkFDFN6TCBEI= | ||||
| github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= | ||||
| github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= | ||||
| github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||||
| github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||||
| go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= | ||||
| go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= | ||||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= | ||||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= | ||||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 h1:yd02MEjBdJkG3uabWP9apV+OuWRIXGDuJEUJbOHmCFU= | ||||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0/go.mod h1:umTcuxiv1n/s/S6/c2AT/g2CQ7u5C59sHDNmfSwgz7Q= | ||||
| go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= | ||||
| go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= | ||||
| go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw= | ||||
| go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= | ||||
| go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= | ||||
| go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= | ||||
| go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ= | ||||
| go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M= | ||||
| go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= | ||||
| go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= | ||||
| go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM= | ||||
| go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM= | ||||
| go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= | ||||
| go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= | ||||
| go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s= | ||||
| go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck= | ||||
| go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= | ||||
| go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= | ||||
| go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= | ||||
| @@ -167,24 +202,37 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL | ||||
| golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= | ||||
| golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= | ||||
| golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= | ||||
| golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= | ||||
| golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= | ||||
| golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= | ||||
| golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= | ||||
| golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70= | ||||
| golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= | ||||
| golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||||
| golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= | ||||
| golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= | ||||
| golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= | ||||
| golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= | ||||
| golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= | ||||
| golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= | ||||
| golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= | ||||
| golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||||
| golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= | ||||
| golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= | ||||
| golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ= | ||||
| golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| @@ -193,6 +241,7 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY | ||||
| golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= | ||||
| golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= | ||||
| golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= | ||||
| golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= | ||||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| @@ -207,6 +256,8 @@ google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= | ||||
| google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= | ||||
| google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= | ||||
| google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= | ||||
| google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU= | ||||
| google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= | ||||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= | ||||
|   | ||||
| @@ -208,6 +208,7 @@ func (r *DeploymentDefaultsReconciler) SetupWithManager(mgr ctrl.Manager) error | ||||
| 	r.Recorder = mgr.GetEventRecorderFor("deploymentdefaults-controller") | ||||
|  | ||||
| 	return ctrl.NewControllerManagedBy(mgr). | ||||
| 		Named("deploymentdefaults"). | ||||
| 		For(&appsv1.Deployment{}). | ||||
| 		Watches( | ||||
| 			&configv1alpha1.NodeTainterConfig{}, | ||||
|   | ||||
							
								
								
									
										221
									
								
								internal/controller/imageupdate_controller.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										221
									
								
								internal/controller/imageupdate_controller.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,221 @@ | ||||
| // internal/controller/imageupdate_controller.go | ||||
| package controller | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	appsv1 "k8s.io/api/apps/v1" | ||||
| 	corev1 "k8s.io/api/core/v1" | ||||
| 	"k8s.io/apimachinery/pkg/api/errors" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	ctrl "sigs.k8s.io/controller-runtime" | ||||
| 	"sigs.k8s.io/controller-runtime/pkg/client" | ||||
| 	"sigs.k8s.io/controller-runtime/pkg/log" | ||||
|  | ||||
| 	configv1alpha1 "git.vendetti.ru/andy/operator/api/v1alpha1" | ||||
|  | ||||
| 	"github.com/google/go-containerregistry/pkg/crane" | ||||
| 	"github.com/google/go-containerregistry/pkg/name" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	DefaultRestartAnnotation = "andy.vendetti.ru/restartedAt" | ||||
| ) | ||||
|  | ||||
| // ImageUpdateReconciler reconciles Deployment objects to check for image updates. | ||||
| type ImageUpdateReconciler struct { | ||||
| 	client.Client | ||||
| 	Scheme   *runtime.Scheme | ||||
| 	Recorder record.EventRecorder | ||||
| } | ||||
|  | ||||
| // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;update;patch | ||||
| // +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch | ||||
| // +kubebuilder:rbac:groups=operator.andy.vendetti.ru,resources=nodetainterconfigs,verbs=get;list;watch | ||||
| // +kubebuilder:rbac:groups="",resources=events,verbs=create;patch | ||||
|  | ||||
| func (r *ImageUpdateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||||
| 	log := log.FromContext(ctx).WithValues("deployment", req.NamespacedName) | ||||
|  | ||||
| 	var config configv1alpha1.NodeTainterConfig | ||||
| 	configKey := types.NamespacedName{Name: GlobalTaintConfigName} | ||||
| 	if err := r.Get(ctx, configKey, &config); err != nil { | ||||
| 		if !errors.IsNotFound(err) { | ||||
| 			log.Error(err, "Failed to get NodeTainterConfig for image updates", "configName", GlobalTaintConfigName) | ||||
| 			return ctrl.Result{}, err | ||||
| 		} | ||||
| 		log.V(1).Info("Global NodeTainterConfig not found, image update checks skipped.", "configName", GlobalTaintConfigName) | ||||
| 		return ctrl.Result{}, nil | ||||
| 	} | ||||
|  | ||||
| 	if config.Spec.ImageUpdatePolicy == nil || !config.Spec.ImageUpdatePolicy.Enabled { | ||||
| 		log.V(1).Info("Image update policy is disabled in NodeTainterConfig.") | ||||
| 		return ctrl.Result{}, nil | ||||
| 	} | ||||
|  | ||||
| 	policy := config.Spec.ImageUpdatePolicy | ||||
| 	if len(policy.MonitoredTags) == 0 { | ||||
| 		log.V(1).Info("No monitored tags configured in ImageUpdatePolicy.") | ||||
| 		return ctrl.Result{}, nil | ||||
| 	} | ||||
|  | ||||
| 	var deployment appsv1.Deployment | ||||
| 	if err := r.Get(ctx, req.NamespacedName, &deployment); err != nil { | ||||
| 		if errors.IsNotFound(err) { | ||||
| 			log.Info("Deployment not found. Ignoring.") | ||||
| 			return ctrl.Result{}, nil | ||||
| 		} | ||||
| 		log.Error(err, "Failed to get Deployment") | ||||
| 		return ctrl.Result{}, err | ||||
| 	} | ||||
|  | ||||
| 	log.V(1).Info("Checking deployment for image updates") | ||||
| 	needsRestart := false | ||||
| 	restartAnnotation := policy.RestartAnnotation | ||||
| 	if restartAnnotation == "" { | ||||
| 		restartAnnotation = DefaultRestartAnnotation | ||||
| 	} | ||||
|  | ||||
| 	podList, err := r.findPodsForDeployment(ctx, &deployment) | ||||
| 	if err != nil { | ||||
| 		log.Error(err, "Failed to list pods for deployment") | ||||
| 		return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil | ||||
| 	} | ||||
|  | ||||
| 	for _, container := range deployment.Spec.Template.Spec.Containers { | ||||
| 		containerLog := log.WithValues("container", container.Name, "image", container.Image) | ||||
|  | ||||
| 		imageName, imageTag, isMonitored := r.parseImageAndCheckTag(container.Image, policy.MonitoredTags) | ||||
| 		if !isMonitored { | ||||
| 			containerLog.V(1).Info("Image tag is not monitored, skipping.") | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		currentDigest, err := r.findCurrentImageDigest(container.Name, podList) | ||||
| 		if err != nil { | ||||
| 			containerLog.Error(err, "Could not determine current image digest from running pods") | ||||
| 			continue | ||||
| 		} | ||||
| 		if currentDigest == "" { | ||||
| 			containerLog.V(1).Info("No running pods found with imageID for this container, skipping check.") | ||||
| 			continue | ||||
| 		} | ||||
| 		containerLog = containerLog.WithValues("currentDigest", currentDigest) | ||||
|  | ||||
| 		latestDigest, err := crane.Digest(imageName + ":" + imageTag) | ||||
| 		if err != nil { | ||||
| 			containerLog.Error(err, "Failed to get latest digest from registry", "image", imageName+":"+imageTag) | ||||
| 			r.Recorder.Eventf(&deployment, corev1.EventTypeWarning, "RegistryError", "Failed to fetch digest for %s:%s: %v", imageName, imageTag, err) | ||||
| 			continue | ||||
| 		} | ||||
| 		containerLog = containerLog.WithValues("latestDigest", latestDigest) | ||||
|  | ||||
| 		if currentDigest != latestDigest { | ||||
| 			containerLog.Info("Image update detected!", "image", imageName+":"+imageTag) | ||||
| 			r.Recorder.Eventf(&deployment, corev1.EventTypeNormal, "UpdateAvailable", "New digest %s detected for image %s:%s (current: %s)", latestDigest, imageName, imageTag, currentDigest) | ||||
| 			needsRestart = true | ||||
| 			break | ||||
| 		} else { | ||||
| 			containerLog.V(1).Info("Image is up-to-date.") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if needsRestart { | ||||
| 		deploymentCopy := deployment.DeepCopy() | ||||
| 		if deploymentCopy.Spec.Template.Annotations == nil { | ||||
| 			deploymentCopy.Spec.Template.Annotations = make(map[string]string) | ||||
| 		} | ||||
| 		restartValue := time.Now().Format(time.RFC3339) | ||||
| 		deploymentCopy.Spec.Template.Annotations[restartAnnotation] = restartValue | ||||
|  | ||||
| 		log.Info("Triggering deployment restart due to image update", "annotationKey", restartAnnotation, "annotationValue", restartValue) | ||||
| 		if err := r.Patch(ctx, deploymentCopy, client.MergeFrom(&deployment)); err != nil { | ||||
| 			log.Error(err, "Failed to patch Deployment to trigger restart") | ||||
| 			r.Recorder.Eventf(&deployment, corev1.EventTypeWarning, "UpdateFailed", "Failed to trigger restart: %v", err) | ||||
| 			return ctrl.Result{}, err | ||||
| 		} | ||||
| 		log.Info("Deployment patched successfully to trigger restart.") | ||||
| 		r.Recorder.Eventf(&deployment, corev1.EventTypeNormal, "RestartTriggered", "Triggered restart due to updated image") | ||||
| 	} | ||||
|  | ||||
| 	checkInterval, err := time.ParseDuration(policy.CheckInterval) | ||||
| 	if err != nil { | ||||
| 		log.Error(err, "Failed to parse CheckInterval from config, using default 1h", "configuredInterval", policy.CheckInterval) | ||||
| 		checkInterval = time.Hour // Fallback | ||||
| 	} | ||||
|  | ||||
| 	log.V(1).Info("Requeuing deployment for next check", "after", checkInterval.String()) | ||||
| 	return ctrl.Result{RequeueAfter: checkInterval}, nil | ||||
| } | ||||
|  | ||||
| func (r *ImageUpdateReconciler) parseImageAndCheckTag(image string, monitoredTags []string) (imgName, imgTag string, monitored bool) { | ||||
| 	ref, err := name.ParseReference(image, name.WeakValidation) | ||||
| 	if err != nil { | ||||
| 		return "", "", false | ||||
| 	} | ||||
|  | ||||
| 	imgName = ref.Context().Name() | ||||
| 	imgTag = ref.Identifier() | ||||
|  | ||||
| 	if strings.HasPrefix(imgTag, "sha256:") { | ||||
| 		return imgName, imgTag, false | ||||
| 	} | ||||
|  | ||||
| 	for _, monitoredKeyword := range monitoredTags { | ||||
| 		if strings.Contains(imgTag, monitoredKeyword) { | ||||
| 			return imgName, imgTag, true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return imgName, imgTag, false | ||||
| } | ||||
|  | ||||
| func (r *ImageUpdateReconciler) findPodsForDeployment(ctx context.Context, deployment *appsv1.Deployment) (*corev1.PodList, error) { | ||||
| 	selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to convert deployment selector: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	podList := &corev1.PodList{} | ||||
| 	err = r.List(ctx, podList, client.InNamespace(deployment.Namespace), client.MatchingLabelsSelector{Selector: selector}) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to list pods: %w", err) | ||||
| 	} | ||||
| 	return podList, nil | ||||
| } | ||||
|  | ||||
| func (r *ImageUpdateReconciler) findCurrentImageDigest(containerName string, podList *corev1.PodList) (string, error) { | ||||
| 	for _, pod := range podList.Items { | ||||
| 		if pod.Status.Phase != corev1.PodRunning && pod.Status.Phase != corev1.PodPending { | ||||
| 			continue | ||||
| 		} | ||||
| 		for _, cs := range pod.Status.ContainerStatuses { | ||||
| 			if cs.Name == containerName && cs.ImageID != "" { | ||||
| 				parts := strings.SplitN(cs.ImageID, "@", 2) | ||||
| 				if len(parts) == 2 && strings.HasPrefix(parts[1], "sha256:") { | ||||
| 					return parts[1], nil | ||||
| 				} | ||||
| 				if strings.HasPrefix(cs.ImageID, "sha256:") { | ||||
| 					return cs.ImageID, nil | ||||
| 				} | ||||
| 				return "", fmt.Errorf("unrecognized imageID format in pod %s: %s", pod.Name, cs.ImageID) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return "", nil | ||||
| } | ||||
|  | ||||
| func (r *ImageUpdateReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||||
| 	r.Recorder = mgr.GetEventRecorderFor("imageupdate-controller") | ||||
|  | ||||
| 	return ctrl.NewControllerManagedBy(mgr). | ||||
| 		Named("imageupdate"). | ||||
| 		For(&appsv1.Deployment{}). | ||||
| 		Complete(r) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user