operator-framework / api

Contains the API definitions used by OLM and Marketplace
Apache License 2.0
29 stars 73 forks source link

IPv6 Address Wrapping Issue in CatalogSource Resource #363

Closed dhirajlakhane30 closed 1 month ago

dhirajlakhane30 commented 1 month ago

Bug Report

There is an issue in the Operator-SDK regarding how IPv6 addresses are handled in the CatalogSource resource. Specifically, the address field in the CatalogSourceStatus struct is not properly wrapped in square brackets [] when dealing with IPv6 addresses. This leads to potential connection issues when the CatalogSource is deployed with an IPv6 address, as the address format is not compliant with the expected format <[IPv6 address]>:.

issue

When i tried to run the bundle (which is pushed to quay.io) on my ipv6 k8s/ocp cluster, it is creating operator group, subscription, catalogsource etc. but when I describe the catalog source there I can see the issue with ipv6 address.

same bundle when I tried to run on ipv4 cluster, it I running very smoothly.

cause

when i explored the operator-sdk source code ( https://github.com/operator-framework/operator-sdk ) , here in the internal/olm/operator/registry/operator_installer.go file you can see the chunk of code to get the catalog source matching the existence subscription. at line 140 cs := &v1alpha1.CatalogSource{} if err := o.cfg.Client.Get(ctx, catsrcKey, cs); err != nil { return nil, fmt.Errorf("error getting catalog source matching the existing subscription: %w", err) }

this v1alpha1.CatalogSource{} is imported as "github.com/operator-framework/api/pkg/operators/v1alpha1" ( https://github.com/operator-framework/api/tree/master/pkg/operators/v1alpha1 ) in the catalogsource_types.go file, In the function:

func (s *RegistryServiceStatus) Address() string { return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port) }

Currently, the Address() function formats the address string without taking into account the specific formatting required for IPv6 addresses (i.e., wrapping the IPv6 address in square brackets []). This can cause errors in systems that expect the correct IPv6 address format.

expected

When an IPv6 address is used, it must be wrapped in square brackets to distinguish it from the port number.

Current behavior: fd00:abcd::1:5000

Expected behavior: [fd00:abcd::1]:5000

Possible Solution

Modify the Address() function in catalogsource_types.go to detect if the service's address is an IPv6 address, and wrap it in square brackets accordingly. Here's a potential fix:

func (s *RegistryServiceStatus) Address() string { if strings.Contains(s.ServiceName, ":") { // It's an IPv6 address, wrap it in brackets return fmt.Sprintf("[%s.%s.svc]:%s", s.ServiceName, s.ServiceNamespace, s.Port) } return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port) }

catalogsource-ipv4 catalogsource-ipv6

Environment

Kubernetes cluster type:

$ operator-sdk version

operator-sdk version: "v1.33.0"

$ go version (if language is Go)

go version go1.21.0 linux/amd64

$ kubectl version

Client Version: v1.30.4 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.30.4

$ oc version

Client Version: 4.12.42 Kustomize Version: v4.5.7 Server Version: 4.16.10 Kubernetes Version: v1.29.7+4510e9c

openshift-ci[bot] commented 1 month ago

@dhirajlakhane30: The label(s) language/go cannot be applied, because the repository doesn't have them.

In response to [this](https://github.com/operator-framework/api/issues/363): >### Bug Report > >There is an issue in the Operator-SDK regarding how IPv6 addresses are handled in the CatalogSource resource. Specifically, the address field in the CatalogSourceStatus struct is not properly wrapped in square brackets [] when dealing with IPv6 addresses. This leads to potential connection issues when the CatalogSource is deployed with an IPv6 address, as the address format is not compliant with the expected format <[IPv6 address]>:. > >### i >![catalogsource-ipv4](https://github.com/user-attachments/assets/279b1a56-ada6-491a-9d21-1ff99d55c31a) >![catalogsource-ipv6](https://github.com/user-attachments/assets/2267b9eb-172a-4ad6-a9d8-82a2d9bfd779) >ssue >When i tried to run the bundle (which is pushed to quay.io) on my ipv6 k8s/ocp cluster, it is creating operator group, subscription, >catalogsource etc. but when I describe the catalog source there I can see the issue with ipv6 address. > >same bundle when I tried to run on ipv4 cluster, it I running very smoothly. > > >#### cause > >when i explored the operator-sdk source code ( https://github.com/operator-framework/operator-sdk ) , here in the internal/olm/operator/registry/operator_installer.go file you can see the chunk of code to get the catalog source matching the existence subscription. at line 140 >cs := &v1alpha1.CatalogSource{} >if err := o.cfg.Client.Get(ctx, catsrcKey, cs); err != nil { >return nil, fmt.Errorf("error getting catalog source matching the existing subscription: %w", err) >} > >this v1alpha1.CatalogSource{} is imported as "github.com/operator-framework/api/pkg/operators/v1alpha1" >( https://github.com/operator-framework/api/tree/master/pkg/operators/v1alpha1 ) >in the catalogsource_types.go file, >In the function: > >func (s *RegistryServiceStatus) Address() string { >return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port) >} > >Currently, the Address() function formats the address string without taking into account the specific formatting required for IPv6 addresses (i.e., wrapping the IPv6 address in square brackets []). This can cause errors in systems that expect the correct IPv6 address format. > >#### expected > >When an IPv6 address is used, it must be wrapped in square brackets to distinguish it from the port number. > >Current behavior: fd00:abcd::1:5000 > >Expected behavior: [fd00:abcd::1]:5000 > > >#### Possible Solution > >Modify the Address() function in catalogsource_types.go to detect if the service's address is an IPv6 address, and wrap it in square brackets accordingly. Here's a potential fix: > >func (s *RegistryServiceStatus) Address() string { >if strings.Contains(s.ServiceName, ":") { >// It's an IPv6 address, wrap it in brackets >return fmt.Sprintf("[%s.%s.svc]:%s", s.ServiceName, s.ServiceNamespace, s.Port) >} >return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port) >} > > >#### Environment > >**Operator type:** > > > >/language go > >**Kubernetes cluster type:** > > > >`$ operator-sdk version` > >operator-sdk version: "v1.33.0" > >`$ go version` (if language is Go) > >go version go1.21.0 linux/amd64 > >`$ kubectl version` > >Client Version: v1.30.4 >Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 >Server Version: v1.30.4 > >`$ oc version` > >Client Version: 4.12.42 >Kustomize Version: v4.5.7 >Server Version: 4.16.10 >Kubernetes Version: v1.29.7+4510e9c Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.