Skip to content
Merged
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
33 changes: 4 additions & 29 deletions iri/remote/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ package bucket

import (
"context"
"fmt"
"os"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"github.com/ironcore-dev/ironcore/iri/remote/common"
)

const (
Expand All @@ -18,36 +16,13 @@ const (

var WellKnownEndpoints = []string{
"/var/run/iri-bucketbroker.sock",
"/var/run/iri-cephd.sock",
"/var/run/iri-bucketprovider.sock",
}

func GetAddressWithTimeout(timeout time.Duration, explicitAddress string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return GetAddress(ctx, explicitAddress)
return common.GetAddressWithTimeout(timeout, explicitAddress, AddressEnv, WellKnownEndpoints)
}

func GetAddress(ctx context.Context, explicitAddress string) (string, error) {
if explicitAddress != "" {
return explicitAddress, nil
}

if address := os.Getenv(AddressEnv); address != "" {
return address, nil
}

var endpoint string
if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(ctx context.Context) (done bool, err error) {
for _, wellKnownEndpoint := range WellKnownEndpoints {
if stat, err := os.Stat(wellKnownEndpoint); err == nil && stat.Mode().Type()&os.ModeSocket != 0 {
endpoint = wellKnownEndpoint
return true, nil
}
}
return false, nil
}); err != nil {
return "", fmt.Errorf("could not determine which enpdoint to use")
}

return fmt.Sprintf("unix://%s", endpoint), nil
return common.GetAddress(ctx, explicitAddress, AddressEnv, WellKnownEndpoints)
}
44 changes: 44 additions & 0 deletions iri/remote/common/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package common

import (
"context"
"fmt"
"os"
"time"

"k8s.io/apimachinery/pkg/util/wait"
)

func GetAddressWithTimeout(timeout time.Duration, explicitAddress string, addressEnv string, wellKnownEndpoints []string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return GetAddress(ctx, explicitAddress, addressEnv, wellKnownEndpoints)
}

func GetAddress(ctx context.Context, explicitAddress string, addressEnv string, wellKnownEndpoints []string) (string, error) {
if explicitAddress != "" {
return explicitAddress, nil
}

if address := os.Getenv(addressEnv); address != "" {
return address, nil
}

var endpoint string
if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(ctx context.Context) (done bool, err error) {
for _, wellKnownEndpoint := range wellKnownEndpoints {
if stat, err := os.Stat(wellKnownEndpoint); err == nil && stat.Mode().Type()&os.ModeSocket != 0 {
endpoint = wellKnownEndpoint
return true, nil
}
}
return false, nil
}); err != nil {
return "", fmt.Errorf("could not determine which endpoint to use")
}

return fmt.Sprintf("unix://%s", endpoint), nil
}
33 changes: 4 additions & 29 deletions iri/remote/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ package machine

import (
"context"
"fmt"
"os"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"github.com/ironcore-dev/ironcore/iri/remote/common"
)

const (
Expand All @@ -18,36 +16,13 @@ const (

var WellKnownEndpoints = []string{
"/var/run/iri-machinebroker.sock",
"/var/run/iri-virtd.sock",
"/var/run/iri-machineprovider.sock",
}

func GetAddressWithTimeout(timeout time.Duration, explicitAddress string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return GetAddress(ctx, explicitAddress)
return common.GetAddressWithTimeout(timeout, explicitAddress, AddressEnv, WellKnownEndpoints)
}

func GetAddress(ctx context.Context, explicitAddress string) (string, error) {
if explicitAddress != "" {
return explicitAddress, nil
}

if address := os.Getenv(AddressEnv); address != "" {
return address, nil
}

var endpoint string
if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(ctx context.Context) (done bool, err error) {
for _, wellKnownEndpoint := range WellKnownEndpoints {
if stat, err := os.Stat(wellKnownEndpoint); err == nil && stat.Mode().Type()&os.ModeSocket != 0 {
endpoint = wellKnownEndpoint
return true, nil
}
}
return false, nil
}); err != nil {
return "", fmt.Errorf("could not determine which enpdoint to use")
}

return fmt.Sprintf("unix://%s", endpoint), nil
return common.GetAddress(ctx, explicitAddress, AddressEnv, WellKnownEndpoints)
}
33 changes: 4 additions & 29 deletions iri/remote/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ package volume

import (
"context"
"fmt"
"os"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"github.com/ironcore-dev/ironcore/iri/remote/common"
)

const (
Expand All @@ -18,36 +16,13 @@ const (

var WellKnownEndpoints = []string{
"/var/run/iri-volumebroker.sock",
"/var/run/iri-cephd.sock",
"/var/run/iri-volumeprovider.sock",
}

func GetAddressWithTimeout(timeout time.Duration, explicitAddress string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return GetAddress(ctx, explicitAddress)
return common.GetAddressWithTimeout(timeout, explicitAddress, AddressEnv, WellKnownEndpoints)
}

func GetAddress(ctx context.Context, explicitAddress string) (string, error) {
if explicitAddress != "" {
return explicitAddress, nil
}

if address := os.Getenv(AddressEnv); address != "" {
return address, nil
}

var endpoint string
if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(ctx context.Context) (done bool, err error) {
for _, wellKnownEndpoint := range WellKnownEndpoints {
if stat, err := os.Stat(wellKnownEndpoint); err == nil && stat.Mode().Type()&os.ModeSocket != 0 {
endpoint = wellKnownEndpoint
return true, nil
}
}
return false, nil
}); err != nil {
return "", fmt.Errorf("could not determine which enpdoint to use")
}

return fmt.Sprintf("unix://%s", endpoint), nil
return common.GetAddress(ctx, explicitAddress, AddressEnv, WellKnownEndpoints)
}