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
4 changes: 2 additions & 2 deletions cmd/cluster/core/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
kvinfra "github.com/openshift/hypershift/kubevirtexternalinfra"
hyperapi "github.com/openshift/hypershift/support/api"
supportforwarder "github.com/openshift/hypershift/support/forwarder"
supportutil "github.com/openshift/hypershift/support/util"
"github.com/openshift/hypershift/support/netutil"

configv1 "github.com/openshift/api/config/v1"
imagev1 "github.com/openshift/api/image/v1"
Expand Down Expand Up @@ -232,7 +232,7 @@ func dumpGuestCluster(ctx context.Context, opts *DumpOptions) error {
Out: forwarderOutput,
ErrOut: forwarderOutput,
}
podPort := supportutil.KASPodPortFromHostedCluster(hostedCluster)
podPort := netutil.KASPodPortFromHostedCluster(hostedCluster)
forwarderStop = make(chan struct{})
if err := forwarder.ForwardPorts([]string{fmt.Sprintf("%d:%d", localPort, podPort)}, forwarderStop); err != nil {
return fmt.Errorf("cannot forward kube apiserver port: %w, output: %s", err, forwarderOutput.String())
Expand Down
6 changes: 3 additions & 3 deletions cmd/kubeconfig/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/cmd/util"
hyperutil "github.com/openshift/hypershift/support/util"
"github.com/openshift/hypershift/support/netutil"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -120,7 +120,7 @@ func Render(ctx context.Context, namespace string, name string, portForward bool
if !hasData || len(data) == 0 {
return fmt.Errorf("kubeconfig secret has no kubeconfig")
}
if portForward && hyperutil.IsPrivateHC(&cluster) {
if portForward && netutil.IsPrivateHC(&cluster) {
data, err = rewriteServerForPrivateCluster(ctx, c, &cluster, data)
if err != nil {
return fmt.Errorf("failed to rewrite kubeconfig for private cluster: %w", err)
Expand Down Expand Up @@ -175,7 +175,7 @@ func buildCombinedConfig(ctx context.Context, c client.Client, namespace string,
log.Printf("missing kubeconfig contents")
continue
}
if portForward && hyperutil.IsPrivateHC(&cluster) {
if portForward && netutil.IsPrivateHC(&cluster) {
var err error
data, err = rewriteServerForPrivateCluster(ctx, c, &cluster, data)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oadp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/openshift/hypershift/api/hypershift/v1beta1"
utilroute "github.com/openshift/hypershift/support/util"
"github.com/openshift/hypershift/support/netutil"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -171,7 +171,7 @@ func (o *CreateOptions) buildBackupSpec(includedNamespaces, includedResources []
func generateName(hcName, hcNamespace string) string {
randomSuffix := utilrand.String(6)
baseName := fmt.Sprintf("%s-%s", hcName, hcNamespace)
return utilroute.ShortenName(baseName, randomSuffix, validation.DNS1123LabelMaxLength)
return netutil.ShortenName(baseName, randomSuffix, validation.DNS1123LabelMaxLength)
}

// GenerateResourcePolicyName creates a deterministic resource policy ConfigMap name
Expand All @@ -182,7 +182,7 @@ func GenerateResourcePolicyName(hcName, hcNamespace string) string {
baseName := fmt.Sprintf("%s-%s", hcName, hcNamespace)
hash := sha256.Sum256([]byte(baseName))
hashSuffix := hex.EncodeToString(hash[:])[:6]
return utilroute.ShortenName(baseName, hashSuffix, validation.DNS1123LabelMaxLength)
return netutil.ShortenName(baseName, hashSuffix, validation.DNS1123LabelMaxLength)
}

// GenerateResourcePolicyConfigMap creates a ConfigMap with a Velero volume policy that skips
Expand Down
4 changes: 2 additions & 2 deletions cmd/oadp/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/openshift/hypershift/cmd/log"
"github.com/openshift/hypershift/cmd/util"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/oadp"
utilroute "github.com/openshift/hypershift/support/util"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
utilrand "k8s.io/apimachinery/pkg/util/rand"
Expand Down Expand Up @@ -101,7 +101,7 @@ func GenerateRestoreName(hcName, hcNamespace string) string {
randomSuffix := utilrand.String(6)
baseName := fmt.Sprintf("%s-%s", hcName, hcNamespace)
// Use ShortenName to ensure it doesn't exceed DNS1123 subdomain max length (63 chars)
return utilroute.ShortenName(baseName, randomSuffix, validation.DNS1123LabelMaxLength)
return netutil.ShortenName(baseName, randomSuffix, validation.DNS1123LabelMaxLength)
}

func (o *CreateOptions) RunRestore(ctx context.Context) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/openshift/hypershift/support/awsapi"
supportawsutil "github.com/openshift/hypershift/support/awsutil"
"github.com/openshift/hypershift/support/config"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/upsert"
"github.com/openshift/hypershift/support/util"

Expand Down Expand Up @@ -764,7 +765,7 @@ func (r *AWSEndpointServiceReconciler) reconcileAWSEndpointService(ctx context.C
awsEndpointService.Status.DNSNames = fqdns
awsEndpointService.Status.DNSZoneID = zoneID

if isPublic, externalNames := util.IsPublicHCP(hcp), hcpExternalNames(hcp); !isPublic && len(externalNames) > 0 {
if isPublic, externalNames := netutil.IsPublicHCP(hcp), hcpExternalNames(hcp); !isPublic && len(externalNames) > 0 {
// only if not public and external names are configured, create services of type ExternalName so external-dns
// can create records for them
var errs []error
Expand Down Expand Up @@ -967,12 +968,12 @@ func reconcileExternalService(svc *corev1.Service, hcp *hyperv1.HostedControlPla

func hcpExternalNames(hcp *hyperv1.HostedControlPlane) map[string]string {
result := map[string]string{}
apiStrategy := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
apiStrategy := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
if apiStrategy != nil && apiStrategy.Type == hyperv1.Route && apiStrategy.Route != nil && apiStrategy.Route.Hostname != "" {
result["api"] = apiStrategy.Route.Hostname
}

oauthStrategy := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.OAuthServer)
oauthStrategy := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.OAuthServer)
if oauthStrategy != nil && oauthStrategy.Type == hyperv1.Route && oauthStrategy.Route != nil && oauthStrategy.Route.Hostname != "" {
result["oauth"] = oauthStrategy.Route.Hostname
}
Expand All @@ -998,7 +999,7 @@ func recordsForService(awsEndpointService *hyperv1.AWSEndpointService, hcp *hype

// If the kas is exposed through a route, the router needs to have DNS entries for both
// the kas and the apps domain
if m := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer); m != nil && m.Type == hyperv1.Route {
if m := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer); m != nil && m.Type == hyperv1.Route {
return []string{"api", "*." + routerDomain}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests"
"github.com/openshift/hypershift/support/config"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/upsert"
"github.com/openshift/hypershift/support/util"

Expand Down Expand Up @@ -455,7 +456,7 @@ func (r *GCPPrivateServiceConnectReconciler) cleanupDNS(ctx context.Context, gcp
// reconcileExternalServices creates external-dns services for private clusters with external names
// This enables external-dns to create DNS records for private PSC endpoints with custom hostnames
func (r *GCPPrivateServiceConnectReconciler) reconcileExternalServices(ctx context.Context, gcpPSC *hyperv1.GCPPrivateServiceConnect, hcp *hyperv1.HostedControlPlane, log logr.Logger) (ctrl.Result, error) { //nolint:unparam // result kept for interface/API consistency
if isPublic, externalNames := util.IsPublicHCP(hcp), hcpExternalNamesGCP(hcp); !isPublic && len(externalNames) > 0 {
if isPublic, externalNames := netutil.IsPublicHCP(hcp), hcpExternalNamesGCP(hcp); !isPublic && len(externalNames) > 0 {
// Only if not public and external names are configured, create services of type ExternalName so external-dns
// can create records for them
var errs []error
Expand Down Expand Up @@ -504,12 +505,12 @@ func (r *GCPPrivateServiceConnectReconciler) reconcileExternalServices(ctx conte
// hcpExternalNamesGCP extracts external hostnames from HCP configuration for GCP
func hcpExternalNamesGCP(hcp *hyperv1.HostedControlPlane) map[string]string {
result := map[string]string{}
apiStrategy := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
apiStrategy := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
if apiStrategy != nil && apiStrategy.Type == hyperv1.Route && apiStrategy.Route != nil && apiStrategy.Route.Hostname != "" {
result["api"] = apiStrategy.Route.Hostname
}

oauthStrategy := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.OAuthServer)
oauthStrategy := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.OAuthServer)
if oauthStrategy != nil && oauthStrategy.Type == hyperv1.Route && oauthStrategy.Route != nil && oauthStrategy.Route.Hostname != "" {
result["oauth"] = oauthStrategy.Route.Hostname
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package openstack

import (
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/support/util"
"github.com/openshift/hypershift/support/netutil"

corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -67,7 +67,7 @@ func getCloudConfig(platformSpec *hyperv1.OpenStackPlatformSpec, credentialsSecr
}
}
config += "\n[Networking]\n"
config += "address-sort-order = " + util.MachineNetworksToList(machineNetwork) + "\n"
config += "address-sort-order = " + netutil.MachineNetworksToList(machineNetwork) + "\n"

return config
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import (
"github.com/openshift/hypershift/support/globalconfig"
karpenterutil "github.com/openshift/hypershift/support/karpenter"
"github.com/openshift/hypershift/support/metrics"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/upsert"
"github.com/openshift/hypershift/support/util"
Expand Down Expand Up @@ -681,9 +682,9 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
Reason: hyperv1.StatusUnknownReason,
}

kasExternalHostname := util.ServiceExternalDNSHostname(hostedControlPlane, hyperv1.APIServer)
kasExternalHostname := netutil.ServiceExternalDNSHostname(hostedControlPlane, hyperv1.APIServer)
if kasExternalHostname != "" {
if err := util.ResolveDNSHostname(ctx, kasExternalHostname); err != nil {
if err := netutil.ResolveDNSHostname(ctx, kasExternalHostname); err != nil {
newCondition = metav1.Condition{
Type: string(hyperv1.ExternalDNSReachable),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -911,13 +912,13 @@ func reconcileAvailabilityStatus(
// healthCheckKASLoadBalancers performs a health check on the KubeAPI server /healthz endpoint using the public and private load balancers hostnames directly
// This will detect if load balancers are down or deleted out of band
func (r *HostedControlPlaneReconciler) healthCheckKASLoadBalancers(ctx context.Context, hcp *hyperv1.HostedControlPlane) error {
serviceStrategy := util.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
serviceStrategy := netutil.ServicePublishingStrategyByTypeForHCP(hcp, hyperv1.APIServer)
if serviceStrategy == nil {
return fmt.Errorf("APIServer service strategy not specified")
}

switch {
case !util.IsPublicHCP(hcp):
case !netutil.IsPublicHCP(hcp):
// When the cluster is private, checking the load balancers will depend on whether the load balancer is
// using the right subnets. To avoid uncertainty, we'll limit the check to the service endpoint.
if hcp.Spec.Platform.Type == hyperv1.IBMCloudPlatform {
Expand Down Expand Up @@ -1647,7 +1648,7 @@ func (r *HostedControlPlaneReconciler) reconcilePKI(ctx context.Context, hcp *hy
// cert secret ourselves.

// Multus Admission Controller Serving Cert - only if Multus is not disabled
if !util.IsDisableMultiNetwork(hcp) {
if !netutil.IsDisableMultiNetwork(hcp) {
multusAdmissionControllerService := manifests.MultusAdmissionControllerService(hcp.Namespace)
if err = r.Get(ctx, client.ObjectKeyFromObject(multusAdmissionControllerService), multusAdmissionControllerService); err != nil {
if !apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -1940,7 +1941,7 @@ func (r *HostedControlPlaneReconciler) cleanupClusterNetworkOperatorResources(ct
// CNO manages overall multus-admission-controller deployment. CPO manages restarts.
// TODO: why is this not done in CNO?
// Only restart multus deployment if Multus is not disabled
if !util.IsDisableMultiNetwork(hcp) {
if !netutil.IsDisableMultiNetwork(hcp) {
multusDeployment := manifests.MultusAdmissionControllerDeployment(hcp.Namespace)
if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, multusDeployment, restartAnnotation); err != nil {
return fmt.Errorf("failed to restart multus admission controller: %w", err)
Expand Down Expand Up @@ -2140,7 +2141,7 @@ func (r *HostedControlPlaneReconciler) removeHCPIngressFromRoutes(ctx context.Co

for i := range routeList.Items {
route := &routeList.Items[i]
if _, hasHCPLabel := route.Labels[util.HCPRouteLabel]; hasHCPLabel {
if _, hasHCPLabel := route.Labels[netutil.HCPRouteLabel]; hasHCPLabel {
// Skip routes that should be managed by the HCP router
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
fakecapabilities "github.com/openshift/hypershift/support/capabilities/fake"
"github.com/openshift/hypershift/support/certs"
controlplanecomponent "github.com/openshift/hypershift/support/controlplane-component"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/releaseinfo"
fakereleaseprovider "github.com/openshift/hypershift/support/releaseinfo/fake"
"github.com/openshift/hypershift/support/releaseinfo/testutils"
Expand Down Expand Up @@ -1841,7 +1842,7 @@ func TestRemoveHCPIngressFromRoutes(t *testing.T) {
Name: "hcp-managed-route",
Namespace: namespace,
Labels: map[string]string{
util.HCPRouteLabel: namespace,
netutil.HCPRouteLabel: namespace,
},
},
Status: routev1.RouteStatus{
Expand All @@ -1858,7 +1859,7 @@ func TestRemoveHCPIngressFromRoutes(t *testing.T) {
Name: "hcp-managed-route",
Namespace: namespace,
Labels: map[string]string{
util.HCPRouteLabel: namespace,
netutil.HCPRouteLabel: namespace,
},
},
Status: routev1.RouteStatus{
Expand Down Expand Up @@ -1990,7 +1991,7 @@ func TestRemoveHCPIngressFromRoutes(t *testing.T) {
Name: "hcp-managed",
Namespace: namespace,
Labels: map[string]string{
util.HCPRouteLabel: namespace,
netutil.HCPRouteLabel: namespace,
},
},
Status: routev1.RouteStatus{
Expand Down Expand Up @@ -2029,7 +2030,7 @@ func TestRemoveHCPIngressFromRoutes(t *testing.T) {
Name: "hcp-managed",
Namespace: namespace,
Labels: map[string]string{
util.HCPRouteLabel: namespace,
netutil.HCPRouteLabel: namespace,
},
},
Status: routev1.RouteStatus{
Expand Down
Loading
Loading