diff --git a/go.mod b/go.mod index 3cfeb2202b..3510f4af90 100644 --- a/go.mod +++ b/go.mod @@ -128,3 +128,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/openshift/library-go => github.com/haircommander/library-go v0.0.0-20241121174603-6f09d18c18d4 diff --git a/go.sum b/go.sum index 808510b03d..6f3b462f04 100644 --- a/go.sum +++ b/go.sum @@ -123,6 +123,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/haircommander/library-go v0.0.0-20241121174603-6f09d18c18d4 h1:duMryvic5BNglJvFt3nrWYt3yFTClYBVZEfuHBA61co= +github.com/haircommander/library-go v0.0.0-20241121174603-6f09d18c18d4/go.mod h1:l/3SegTa9x+ry2J213bh7+DBofXOOvdrqU4JC9ktJa0= github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= @@ -167,8 +169,6 @@ github.com/openshift/build-machinery-go v0.0.0-20240613134303-8359781da660 h1:F0 github.com/openshift/build-machinery-go v0.0.0-20240613134303-8359781da660/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE= github.com/openshift/client-go v0.0.0-20241001162912-da6d55e4611f h1:FRc0bVNWprihWS0GqQWzb3dY4dkCwpOP3mDw5NwSoR4= github.com/openshift/client-go v0.0.0-20241001162912-da6d55e4611f/go.mod h1:KiZi2mJRH1TOJ3FtBDYS6YvUL30s/iIXaGSUrSa36mo= -github.com/openshift/library-go v0.0.0-20241119162247-f466fdd82330 h1:nK16PhWNPIjnv7Vux1jBlzEPgA9q/o/CwqsbRpQJrpY= -github.com/openshift/library-go v0.0.0-20241119162247-f466fdd82330/go.mod h1:9B1MYPoLtP9tqjWxcbUNVpwxy68zOH/3EIP6c31dAM0= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/vendor/github.com/openshift/library-go/pkg/operator/configobserver/node/observe_minimum_kubelet_version.go b/vendor/github.com/openshift/library-go/pkg/operator/configobserver/node/observe_minimum_kubelet_version.go new file mode 100644 index 0000000000..ea37c99113 --- /dev/null +++ b/vendor/github.com/openshift/library-go/pkg/operator/configobserver/node/observe_minimum_kubelet_version.go @@ -0,0 +1,47 @@ +package node + +import ( + configv1 "github.com/openshift/api/config/v1" + "github.com/openshift/library-go/pkg/operator/configobserver" + "github.com/openshift/library-go/pkg/operator/events" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/klog/v2" +) + +var minimumKubeletVersionConfigPath = "minimumKubeletVersion" + +// ObserveKubeletMinimumVersion watches the node configuration and generates the minimumKubeletVersion +func ObserveMinimumKubeletVersion(genericListers configobserver.Listers, _ events.Recorder, existingConfig map[string]interface{}) (ret map[string]interface{}, errs []error) { + defer func() { + // Prune the observed config so that it only contains minimumKubeletVersion field. + ret = configobserver.Pruned(ret, []string{minimumKubeletVersionConfigPath}) + }() + nodeLister := genericListers.(NodeLister) + configNode, err := nodeLister.NodeLister().Get("cluster") + // we got an error so without the node object we are not able to determine minimumKubeletVersion + if err != nil { + // if config/v1/node/cluster object is not found, that can be treated as a non-error case, but raise a warning + if apierrors.IsNotFound(err) { + klog.Warningf("ObserveMinimumKubeletVersion: nodes.%s/cluster not found", configv1.GroupName) + } else { + errs = append(errs, err) + } + return existingConfig, errs + } + + if configNode.Spec.MinimumKubeletVersion == "" { + // in case minimum kubelet version is not set on cluster + // return empty set of configs, this helps to unset the config + // values related to the minimumKubeletVersion. + // Also, ensures that this observer doesn't break cluster upgrades/downgrades + return map[string]interface{}{}, errs + } + + ret = map[string]interface{}{} + if err := unstructured.SetNestedField(ret, configNode.Spec.MinimumKubeletVersion, minimumKubeletVersionConfigPath); err != nil { + errs = append(errs, err) + } + + return ret, errs +} diff --git a/vendor/github.com/openshift/library-go/pkg/operator/events/recorder.go b/vendor/github.com/openshift/library-go/pkg/operator/events/recorder.go index d4341a5904..2918012ff5 100644 --- a/vendor/github.com/openshift/library-go/pkg/operator/events/recorder.go +++ b/vendor/github.com/openshift/library-go/pkg/operator/events/recorder.go @@ -2,6 +2,7 @@ package events import ( "context" + "crypto/sha256" "errors" "fmt" "k8s.io/client-go/kubernetes" @@ -224,7 +225,7 @@ func makeEvent(clock clock.PassiveClock, involvedObjRef *corev1.ObjectReference, event := &corev1.Event{ ObjectMeta: metav1.ObjectMeta{ // TODO this is always used to create a unique event. Perhaps we should hash the message to be unique enough for apply-configuration - Name: fmt.Sprintf("%v.%x", involvedObjRef.Name, currentTime.UnixNano()), + Name: fmt.Sprintf("%v.%x.%s", involvedObjRef.Name, currentTime.UnixNano(), hashForEventNameSuffix(eventType, reason, message)), Namespace: involvedObjRef.Namespace, }, InvolvedObject: *involvedObjRef, @@ -238,3 +239,20 @@ func makeEvent(clock clock.PassiveClock, involvedObjRef *corev1.ObjectReference, event.Source.Component = sourceComponent return event } + +func hashForEventNameSuffix(in ...string) string { + data := []byte{} + for _, curr := range in { + data = append(data, []byte(curr)...) + } + if len(data) == 0 { + return "MISSING" + } + + hash := sha256.New() + hash.Write(data) + hashBytes := hash.Sum(nil) + + // we're looking to deconflict names, not protect the crown jewels + return fmt.Sprintf("%x", hashBytes[len(hashBytes)-4:]) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index c2ebff9214..224ebaef74 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -349,7 +349,7 @@ github.com/openshift/client-go/security/informers/externalversions/internalinter github.com/openshift/client-go/security/informers/externalversions/security github.com/openshift/client-go/security/informers/externalversions/security/v1 github.com/openshift/client-go/security/listers/security/v1 -# github.com/openshift/library-go v0.0.0-20241119162247-f466fdd82330 +# github.com/openshift/library-go v0.0.0-20241119162247-f466fdd82330 => github.com/haircommander/library-go v0.0.0-20241121174603-6f09d18c18d4 ## explicit; go 1.22.0 github.com/openshift/library-go/pkg/apiserver/jsonpatch github.com/openshift/library-go/pkg/assets @@ -1542,3 +1542,4 @@ sigs.k8s.io/structured-merge-diff/v4/value ## explicit; go 1.12 sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 +# github.com/openshift/library-go => github.com/haircommander/library-go v0.0.0-20241121174603-6f09d18c18d4