@@ -21,6 +21,7 @@ import (
2121 "errors"
2222 "fmt"
2323 "maps"
24+ "net/http"
2425 "reflect"
2526 "strings"
2627 "sync"
@@ -43,7 +44,7 @@ import (
4344 "knative.dev/operator/pkg/apis/operator/base"
4445 "knative.dev/pkg/logging"
4546
46- clusterinventoryv1alpha1 "sigs.k8s.io/cluster-inventory-api/apis/v1alpha1 "
47+ clusterinventoryv1alpha2 "sigs.k8s.io/cluster-inventory-api/apis/v1alpha2 "
4748 clusterinventoryclient "sigs.k8s.io/cluster-inventory-api/client/clientset/versioned"
4849 "sigs.k8s.io/cluster-inventory-api/pkg/access"
4950)
@@ -71,12 +72,13 @@ var (
7172
7273// ClusterProfileAccess builds a rest.Config from a ClusterProfile.
7374type ClusterProfileAccess interface {
74- BuildConfigFromCP (cp * clusterinventoryv1alpha1 .ClusterProfile ) (* rest.Config , error )
75+ BuildConfigFromCP (cp * clusterinventoryv1alpha2 .ClusterProfile ) (* rest.Config , error )
7576}
7677
7778type NoOpClusterProfileAccess struct {}
7879
79- func (NoOpClusterProfileAccess ) BuildConfigFromCP (* clusterinventoryv1alpha1.ClusterProfile ) (* rest.Config , error ) {
80+ // BuildConfigFromCP returns an error because multi-cluster support is disabled.
81+ func (NoOpClusterProfileAccess ) BuildConfigFromCP (* clusterinventoryv1alpha2.ClusterProfile ) (* rest.Config , error ) {
8082 return nil , errMulticlusterDisabled
8183}
8284
@@ -242,7 +244,7 @@ func (c *ClusterProvider) Refresh(ctx context.Context, namespace, name string) (
242244func (c * ClusterProvider ) doRefresh (ctx context.Context , key , namespace , name string ) (string , error ) {
243245 logger := logging .FromContext (ctx )
244246
245- cp , err := c .ciClient .ApisV1alpha1 ().ClusterProfiles (namespace ).Get (
247+ cp , err := c .ciClient .ApisV1alpha2 ().ClusterProfiles (namespace ).Get (
246248 ctx , name , metav1.GetOptions {})
247249 if err != nil {
248250 c .Remove (key )
@@ -395,22 +397,39 @@ func (c *ClusterProvider) GetOrRefresh(ctx context.Context, namespace, name stri
395397 return c .Get (ctx , key )
396398}
397399
398- // configEqual reports whether two rest.Configs have equivalent credentials .
400+ // configEqual reports whether two rest.Configs have equivalent connection settings .
399401func configEqual (a , b * rest.Config ) bool {
400402 return a .Host == b .Host &&
403+ a .DisableCompression == b .DisableCompression &&
401404 reflect .DeepEqual (a .TLSClientConfig , b .TLSClientConfig ) &&
402405 reflect .DeepEqual (a .ExecProvider , b .ExecProvider ) &&
403406 a .BearerToken == b .BearerToken &&
404407 a .BearerTokenFile == b .BearerTokenFile &&
405408 a .Username == b .Username &&
406409 a .Password == b .Password &&
407410 reflect .DeepEqual (a .AuthProvider , b .AuthProvider ) &&
408- reflect .DeepEqual (a .Impersonate , b .Impersonate )
411+ reflect .DeepEqual (a .Impersonate , b .Impersonate ) &&
412+ proxyEqual (a , b )
409413}
410414
411- func isClusterProfileReady (cp * clusterinventoryv1alpha1.ClusterProfile ) bool {
415+ // proxyEqual reports whether two rest.Configs resolve the same proxy for a.Host.
416+ // A nil Proxy uses environment settings; a non-nil Proxy can disable proxying.
417+ func proxyEqual (a , b * rest.Config ) bool {
418+ if a .Proxy == nil || b .Proxy == nil {
419+ return a .Proxy == nil && b .Proxy == nil
420+ }
421+ req , err := http .NewRequest (http .MethodGet , a .Host , nil )
422+ if err != nil {
423+ return false
424+ }
425+ urlA , errA := a .Proxy (req )
426+ urlB , errB := b .Proxy (req )
427+ return errA == nil && errB == nil && reflect .DeepEqual (urlA , urlB )
428+ }
429+
430+ func isClusterProfileReady (cp * clusterinventoryv1alpha2.ClusterProfile ) bool {
412431 cond := apimeta .FindStatusCondition (cp .Status .Conditions ,
413- clusterinventoryv1alpha1 .ClusterConditionControlPlaneHealthy )
432+ clusterinventoryv1alpha2 .ClusterConditionControlPlaneHealthy )
414433 if cond == nil {
415434 return false
416435 }
0 commit comments