diff --git a/.github/workflows/chart-test.yml b/.github/workflows/chart-test.yml index 1aa3e083..d66d932f 100644 --- a/.github/workflows/chart-test.yml +++ b/.github/workflows/chart-test.yml @@ -63,7 +63,7 @@ jobs: - name: Install plugin unittest run: | - helm plugin install https://github.com/helm-unittest/helm-unittest + helm plugin install https://github.com/helm-unittest/helm-unittest --version 1.0.3 # Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and # yamllint (https://github.com/adrienverge/yamllint) which require Python diff --git a/api/v1alpha1/streamnativecloudconnection_types.go b/api/v1alpha1/streamnativecloudconnection_types.go index 2e95b4f8..c74d0ee2 100644 --- a/api/v1alpha1/streamnativecloudconnection_types.go +++ b/api/v1alpha1/streamnativecloudconnection_types.go @@ -25,8 +25,9 @@ import ( // StreamNativeCloudConnectionSpec defines the desired state of StreamNativeCloudConnection type StreamNativeCloudConnectionSpec struct { // Server is the URL of the API server - // +required - Server string `json:"server"` + // +kubebuilder:default="https://api.streamnative.cloud" + // +optional + Server string `json:"server,omitempty"` // Auth defines the authentication configuration // +required @@ -42,6 +43,17 @@ type StreamNativeCloudConnectionSpec struct { Organization string `json:"organization,omitempty"` } +// DefaultStreamNativeCloudServer is the default API server URL +const DefaultStreamNativeCloudServer = "https://api.streamnative.cloud" + +// GetServer returns the server URL, using the default if not specified +func (s *StreamNativeCloudConnectionSpec) GetServer() string { + if s.Server == "" { + return DefaultStreamNativeCloudServer + } + return s.Server +} + // AuthConfig defines the authentication configuration type AuthConfig struct { // CredentialsRef is the reference to the service account credentials secret diff --git a/charts/pulsar-resources-operator/crds/resource.streamnative.io_streamnativecloudconnections.yaml b/charts/pulsar-resources-operator/crds/resource.streamnative.io_streamnativecloudconnections.yaml index 51b3ae68..acb31844 100644 --- a/charts/pulsar-resources-operator/crds/resource.streamnative.io_streamnativecloudconnections.yaml +++ b/charts/pulsar-resources-operator/crds/resource.streamnative.io_streamnativecloudconnections.yaml @@ -109,11 +109,11 @@ spec: If not specified, the operator will use the connection name as the organization type: string server: + default: https://api.streamnative.cloud description: Server is the URL of the API server type: string required: - auth - - server type: object status: description: StreamNativeCloudConnectionStatus defines the observed state diff --git a/config/crd/bases/resource.streamnative.io_streamnativecloudconnections.yaml b/config/crd/bases/resource.streamnative.io_streamnativecloudconnections.yaml index 51b3ae68..acb31844 100644 --- a/config/crd/bases/resource.streamnative.io_streamnativecloudconnections.yaml +++ b/config/crd/bases/resource.streamnative.io_streamnativecloudconnections.yaml @@ -109,11 +109,11 @@ spec: If not specified, the operator will use the connection name as the organization type: string server: + default: https://api.streamnative.cloud description: Server is the URL of the API server type: string required: - auth - - server type: object status: description: StreamNativeCloudConnectionStatus defines the observed state diff --git a/pkg/streamnativecloud/api_connection.go b/pkg/streamnativecloud/api_connection.go index 4a221b30..a68f58eb 100644 --- a/pkg/streamnativecloud/api_connection.go +++ b/pkg/streamnativecloud/api_connection.go @@ -83,7 +83,7 @@ func (c *APIConnection) connect() error { ClientSecret: c.credentials.ClientSecret, TokenURL: config.TokenEndpoint, EndpointParams: url.Values{ - "audience": []string{c.config.Spec.Server}, + "audience": []string{c.config.Spec.GetServer()}, }, } @@ -101,7 +101,7 @@ func (c *APIConnection) Test(ctx context.Context) error { if c.client == nil { return fmt.Errorf("waiting for client") } - req, err := http.NewRequestWithContext(ctx, "GET", c.config.Spec.Server+"/healthz", http.NoBody) + req, err := http.NewRequestWithContext(ctx, "GET", c.config.Spec.GetServer()+"/healthz", http.NoBody) if err != nil { return err } @@ -134,7 +134,7 @@ func (c *APIConnection) NeedsUpdate( if c.credentials == nil { return true } - return c.config.Spec.Server != config.Spec.Server || + return c.config.Spec.GetServer() != config.Spec.GetServer() || c.credentials.ClientID != creds.ClientID || c.credentials.ClientSecret != creds.ClientSecret || c.credentials.IssuerURL != creds.IssuerURL