Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cluster-network-operator/mtu_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newMTUProberCommand() *cobra.Command {
}

// Write the CM in the apiserver, retrying as needed.
for tries := 0; tries < 10; tries++ {
for range 10 {
_, err = clientSet.CoreV1().ConfigMaps(namespace).Create(context.Background(), &cm, metav1.CreateOptions{})
if err != nil && apierrors.IsAlreadyExists(err) {
_, err = clientSet.CoreV1().ConfigMaps(namespace).Update(context.Background(), &cm, metav1.UpdateOptions{})
Expand Down
8 changes: 3 additions & 5 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"maps"
"strings"

cnoclient "github.com/openshift/cluster-network-operator/pkg/client"
Expand All @@ -16,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilpointer "k8s.io/utils/ptr"
)

type Object interface {
Expand Down Expand Up @@ -113,7 +113,7 @@ func ApplyObject(ctx context.Context, client cnoclient.Client, obj Object, subco
// Use server-side apply to merge the desired object with the object on disk
patchOptions := metav1.PatchOptions{
// It is considered best-practice for controllers to force
Force: utilpointer.To(true),
Force: new(true),
FieldManager: fieldManager,
}
// Send the full object to be applied on the server side.
Expand Down Expand Up @@ -188,9 +188,7 @@ func getCopySource(ctx context.Context, obj Object, client cnoclient.Client) (Ob
if annotations == nil {
annotations = make(map[string]string)
}
for k, v := range obj.GetAnnotations() {
annotations[k] = v
}
maps.Copy(annotations, obj.GetAnnotations())
ret.SetAnnotations(annotations)

return ret, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/checkendpoints/controller/backoff_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
// Recorder is a stripped down version of the library-go events.Recorder interface.
type Recorder interface {
Event(reason, message string)
Eventf(reason, messageFmt string, args ...interface{})
Eventf(reason, messageFmt string, args ...any)
Warning(reason, message string)
Warningf(reason, messageFmt string, args ...interface{})
Warningf(reason, messageFmt string, args ...any)
}

// NewBackoffEventRecorder returns a new Recorder that keeps track of the rate of events
Expand Down Expand Up @@ -84,15 +84,15 @@ func (r *backoffEventRecorder) Event(reason, message string) {
r.event(corev1.EventTypeNormal, reason, message)
}

func (r *backoffEventRecorder) Eventf(reason, messageFmt string, args ...interface{}) {
func (r *backoffEventRecorder) Eventf(reason, messageFmt string, args ...any) {
r.Event(reason, fmt.Sprintf(messageFmt, args...))
}

func (r *backoffEventRecorder) Warning(reason, message string) {
r.event(corev1.EventTypeWarning, reason, message)
}

func (r *backoffEventRecorder) Warningf(reason, messageFmt string, args ...interface{}) {
func (r *backoffEventRecorder) Warningf(reason, messageFmt string, args ...any) {
r.Warning(reason, fmt.Sprintf(messageFmt, args...))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/checkendpoints/controller/backoff_recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func TestWithLongWindow(t *testing.T) {
}

// excessive events for long window
for i := 0; i < excessiveEventCount; i++ {
for range excessiveEventCount {
r.Eventf(t.Name(), "TEST")
}

// wait for backoff period to end
<-time.After(backoffDuration)

// some more events
for i := 0; i < 2; i++ {
for range 2 {
r.Eventf(t.Name(), "TEST")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/checkendpoints/controller/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewConnectionChecker(name, podName, podNamespace string, getCheck GetCheckF
clientCertGetter: clientCertGetter,
recorder: recorder,
updates: NewUpdatesManager(checkPeriod, checkTimeout, newUpdatesProcessor(client, name)),
stop: make(chan interface{}),
stop: make(chan any),
metrics: NewMetricsContext(podNamespace, name),
}
}
Expand All @@ -63,7 +63,7 @@ type connectionChecker struct {
clientCertGetter CertificatesGetter
recorder Recorder
updates UpdatesManager
stop chan interface{}
stop chan any
metrics MetricsContext
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func withConnectivityRestoredMessage(start, end int) func(*v1alpha1.OutageEntry)
return withOutageMessage("Connectivity restored after %v", testTime(end).Sub(testTime(start)))
}

func withOutageMessage(msg string, args ...interface{}) func(*v1alpha1.OutageEntry) {
func withOutageMessage(msg string, args ...any) func(*v1alpha1.OutageEntry) {
return func(entry *v1alpha1.OutageEntry) {
entry.Message = fmt.Sprintf(msg, args...)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/eventrecorder/event_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ var _ events.Recorder = &LoggingRecorder{}
func (r *LoggingRecorder) Event(reason, message string) {
log.Println(message)
}
func (r *LoggingRecorder) Eventf(reason, messageFmt string, args ...interface{}) {
func (r *LoggingRecorder) Eventf(reason, messageFmt string, args ...any) {
log.Printf(messageFmt, args...)
}
func (r *LoggingRecorder) Warning(reason, message string) {
log.Println(message)
}

func (r *LoggingRecorder) Warningf(reason, messageFmt string, args ...interface{}) {
func (r *LoggingRecorder) Warningf(reason, messageFmt string, args ...any) {
log.Printf(messageFmt, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/infrastructureconfig/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func validateVipsWithVips(api, ingress []configv1.IP, elb bool) error {

// For external load balancer we allow VIPs to be equal.
if !elb {
for i := 0; i < len(api); i++ {
for i := range api {
if api[i] == ingress[i] {
return fmt.Errorf("VIPs cannot be equal, got '%s' for API and '%s' for Ingress", api[i], ingress[i])
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/observability/observability_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (r *ReconcileObservability) checkOLMv1Installation(ctx context.Context) (in

// Check for "Installed" condition
for _, cond := range conditions {
condMap, ok := cond.(map[string]interface{})
condMap, ok := cond.(map[string]any)
if !ok {
continue
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/controller/observability/observability_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func createTestClusterExtension(t *testing.T, name string, installed bool) *unst
ce.SetName(name)

// Set status conditions
conditions := []interface{}{
map[string]interface{}{
conditions := []any{
map[string]any{
"type": "Installed",
"status": func() string {
if installed {
Expand Down Expand Up @@ -674,8 +674,8 @@ func TestIsNetObservOperatorInstalled_OLMv1InstallationFailed(t *testing.T) {
Kind: "ClusterExtension",
})
ce.SetName("netobserv-operator")
conditions := []interface{}{
map[string]interface{}{
conditions := []any{
map[string]any{
"type": "Installed",
"status": "False",
"reason": "InstallationFailed",
Expand Down Expand Up @@ -715,8 +715,8 @@ func TestIsNetObservOperatorInstalled_OLMv1NotInstalledYet(t *testing.T) {
Kind: "ClusterExtension",
})
ce.SetName("netobserv-operator")
conditions := []interface{}{
map[string]interface{}{
conditions := []any{
map[string]any{
"type": "Installed",
"status": "Unknown",
"reason": "Installing",
Expand Down Expand Up @@ -1468,8 +1468,8 @@ func TestReconcile_RecoveryAfterOperatorBecomesReady(t *testing.T) {
g.Expect(result1.RequeueAfter).To(Equal(requeueAfterStandard))

// Update ClusterExtension to Installed status
conditions := []interface{}{
map[string]interface{}{
conditions := []any{
map[string]any{
"type": "Installed",
"status": "True",
"reason": "InstallSucceeded",
Expand Down Expand Up @@ -1527,7 +1527,7 @@ func TestReconcile_ConcurrentReconciliations(t *testing.T) {

// Run 5 concurrent reconciliations
errChan := make(chan error, 5)
for i := 0; i < 5; i++ {
for range 5 {
go func() {
_, err := r.Reconcile(context.TODO(), req)
errChan <- err
Expand All @@ -1536,7 +1536,7 @@ func TestReconcile_ConcurrentReconciliations(t *testing.T) {

// Wait for all to complete and collect errors
var unexpectedErrors []error
for i := 0; i < 5; i++ {
for range 5 {
if err := <-errChan; err != nil {
// Filter out 409 conflict errors which are expected when multiple
// goroutines try to update the same resource status concurrently
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/proxyconfig/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *ReconcileProxyConfig) ValidateProxyConfig(proxyConfig *configv1.ProxySp

if isSpecNoProxySet(proxyConfig) {
if proxyConfig.NoProxy != noProxyWildcard {
for _, v := range strings.Split(proxyConfig.NoProxy, ",") {
for v := range strings.SplitSeq(proxyConfig.NoProxy, ",") {
v = strings.TrimSpace(v)
errDomain := validation.DomainName(v, true)
errCIDR := validation.IPAddressOrCIDR(v)
Expand Down Expand Up @@ -219,7 +219,7 @@ func validateReadinessEndpoint(caBundle []*x509.Certificate, proxy, endpoint str
// finite loop using proxy and returns the last result if it never succeeds.
func validateReadinessEndpointWithRetries(caBundle []*x509.Certificate, proxy, endpoint *url.URL, retries int) error {
var err error
for i := 0; i < retries; i++ {
for range retries {
err = runReadinessProbe(caBundle, proxy, endpoint)
if err == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/statusmanager/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type patchAnnotations struct {
Metadata md `json:"metadata"`
}
type md struct {
Annotations map[string]interface{} `json:"annotations"`
Annotations map[string]any `json:"annotations"`
}

func (status *StatusManager) setAnnotation(ctx context.Context, obj crclient.Object, key string, value *string) error {
Expand All @@ -48,7 +48,7 @@ func (status *StatusManager) setAnnotation(ctx context.Context, obj crclient.Obj
}
patch := &patchAnnotations{
Metadata: md{
Annotations: map[string]interface{}{
Annotations: map[string]any{
key: value,
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/statusmanager/status_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...operv

buf, err := yaml.Marshal(oc.Status.Conditions)
if err != nil {
buf = []byte(fmt.Sprintf("(failed to convert to YAML: %s)", err))
buf = fmt.Appendf(nil, "(failed to convert to YAML: %s)", err)
}

// Use applyconfigurations to change only the specified fields
Expand Down Expand Up @@ -497,7 +497,7 @@ func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...operv

buf, err := yaml.Marshal(co.Status.Conditions)
if err != nil {
buf = []byte(fmt.Sprintf("(failed to convert to YAML: %s)", err))
buf = fmt.Appendf(nil, "(failed to convert to YAML: %s)", err)
}

if isNotFound {
Expand Down Expand Up @@ -583,7 +583,7 @@ func (status *StatusManager) MaybeSetDegraded(statusLevel StatusLevel, reason, m
status.maybeSetDegraded(statusLevel, reason, message)
}

func (status *StatusManager) SetDegradedOnPanicAndCrash(panicVal interface{}) {
func (status *StatusManager) SetDegradedOnPanicAndCrash(panicVal any) {
status.Lock()
defer status.Unlock()
status.setDegraded(PanicLevel, "ReconcileError", fmt.Sprintf("Panic detected: %v", panicVal))
Expand Down
14 changes: 7 additions & 7 deletions pkg/hypershift/hypershift.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan
return nil, fmt.Errorf("failed extract tolerations: %v", err)
}
if tolerationsArrayFound {
tolerationsArrayConverted, hasConverted := tolerationsArray.([]interface{})
tolerationsArrayConverted, hasConverted := tolerationsArray.([]any)
if hasConverted {
for _, entry := range tolerationsArrayConverted {
tolerationConverted, hasConverted := entry.(map[string]interface{})
tolerationConverted, hasConverted := entry.(map[string]any)
if hasConverted {
toleration := corev1.Toleration{}
raw, ok := tolerationConverted["key"]
Expand Down Expand Up @@ -233,10 +233,10 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan
return nil, fmt.Errorf("failed extract serviceNetwork: %v", err)
}
if cidrArrayValueFound {
cidrArrayConverted, hasConverted := cidrArray.([]interface{})
cidrArrayConverted, hasConverted := cidrArray.([]any)
if hasConverted {
sampleCidrVal := cidrArrayConverted[0]
sampleCidrValConverted, sampleCidrHasConverted := sampleCidrVal.(map[string]interface{})
sampleCidrValConverted, sampleCidrHasConverted := sampleCidrVal.(map[string]any)
if sampleCidrHasConverted {
cidrRawVal, hasCidrKey := sampleCidrValConverted["cidr"]
if hasCidrKey {
Expand Down Expand Up @@ -264,7 +264,7 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan
return nil, fmt.Errorf("failed to extract apiServer config: %v", err)
}
if found && apiServerConfig != nil {
apiServerMap, ok := apiServerConfig.(map[string]interface{})
apiServerMap, ok := apiServerConfig.(map[string]any)
if ok {
var spec configv1.APIServerSpec
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(apiServerMap, &spec); err != nil {
Expand Down Expand Up @@ -396,7 +396,7 @@ func SetHostedControlPlaneConditions(hcp *unstructured.Unstructured, operStatus

// Set the conditions directly instead of using SetNestedField
// because it does a DeepCopy and metav1.Condition doesn't implement it
hcp.Object["status"].(map[string]interface{})["conditions"] = conditions
hcp.Object["status"].(map[string]any)["conditions"] = conditions
return conditions, nil
}

Expand All @@ -415,7 +415,7 @@ func tolerationsToStringSliceYaml(tolerations []corev1.Toleration) ([]string, er
}

yamlStrs := []string{}
for _, arg := range strings.Split(string(yamlBytes), "\n") {
for arg := range strings.SplitSeq(string(yamlBytes), "\n") {

// filter out null and empty strings
if strings.Contains(arg, ": null") || strings.Contains(arg, ": \"\"") {
Expand Down
10 changes: 5 additions & 5 deletions pkg/hypershift/hypershift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ func TestSetRestartDateAnnotation(t *testing.T) {

makeObj := func(apiVersion, kind, name, ns string) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": apiVersion,
"kind": kind,
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": name,
"namespace": ns,
},
"spec": map[string]interface{}{
"template": map[string]interface{}{
"metadata": map[string]interface{}{},
"spec": map[string]any{
"template": map[string]any{
"metadata": map[string]any{},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/additional_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func renderRawCNIConfig(conf *operv1.AdditionalNetworkDefinition, manifestDir st
// validateRaw checks the AdditionalNetwork name and RawCNIConfig.
func validateRaw(conf *operv1.AdditionalNetworkDefinition) []error {
out := []error{}
var rawConfig map[string]interface{}
var rawConfig map[string]any
var err error

if conf.Name == "" {
Expand Down
10 changes: 5 additions & 5 deletions pkg/network/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func TestBootstrap(t *testing.T) {
hcp.SetGroupVersionKind(hypershift.HostedControlPlaneGVK)
hcp.SetName(hostedClusterName)
hcp.SetNamespace(hostedClusterNamespace)
hcp.Object["spec"] = map[string]interface{}{
hcp.Object["spec"] = map[string]any{
"clusterID": "test-cluster-id",
"controllerAvailabilityPolicy": "SingleReplica",
"configuration": map[string]interface{}{
"apiServer": map[string]interface{}{
"tlsSecurityProfile": map[string]interface{}{
"configuration": map[string]any{
"apiServer": map[string]any{
"tlsSecurityProfile": map[string]any{
"type": string(configv1.TLSProfileModernType),
},
"tlsAdherence": string(configv1.TLSAdherencePolicyStrictAllComponents),
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBootstrap(t *testing.T) {
hcp.SetGroupVersionKind(hypershift.HostedControlPlaneGVK)
hcp.SetName(hostedClusterName)
hcp.SetNamespace(hostedClusterNamespace)
hcp.Object["spec"] = map[string]interface{}{
hcp.Object["spec"] = map[string]any{
"clusterID": "test-cluster-id",
"controllerAvailabilityPolicy": "SingleReplica",
}
Expand Down
Loading