Skip to content

Commit b6c60ee

Browse files
authored
feat(api): make server field optional with default (#367)
* feat(api): make server field optional with default * revert copyright change * style(crd): correct copyright year from 2026 to 2025 * ci(chart-test): specify version for helm-unittest plugin
1 parent 2980b26 commit b6c60ee

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

.github/workflows/chart-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363

6464
- name: Install plugin unittest
6565
run: |
66-
helm plugin install https://github.com/helm-unittest/helm-unittest
66+
helm plugin install https://github.com/helm-unittest/helm-unittest --version 1.0.3
6767
6868
# Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and
6969
# yamllint (https://github.com/adrienverge/yamllint) which require Python

api/v1alpha1/streamnativecloudconnection_types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import (
2525
// StreamNativeCloudConnectionSpec defines the desired state of StreamNativeCloudConnection
2626
type StreamNativeCloudConnectionSpec struct {
2727
// Server is the URL of the API server
28-
// +required
29-
Server string `json:"server"`
28+
// +kubebuilder:default="https://api.streamnative.cloud"
29+
// +optional
30+
Server string `json:"server,omitempty"`
3031

3132
// Auth defines the authentication configuration
3233
// +required
@@ -42,6 +43,17 @@ type StreamNativeCloudConnectionSpec struct {
4243
Organization string `json:"organization,omitempty"`
4344
}
4445

46+
// DefaultStreamNativeCloudServer is the default API server URL
47+
const DefaultStreamNativeCloudServer = "https://api.streamnative.cloud"
48+
49+
// GetServer returns the server URL, using the default if not specified
50+
func (s *StreamNativeCloudConnectionSpec) GetServer() string {
51+
if s.Server == "" {
52+
return DefaultStreamNativeCloudServer
53+
}
54+
return s.Server
55+
}
56+
4557
// AuthConfig defines the authentication configuration
4658
type AuthConfig struct {
4759
// CredentialsRef is the reference to the service account credentials secret

charts/pulsar-resources-operator/crds/resource.streamnative.io_streamnativecloudconnections.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ spec:
109109
If not specified, the operator will use the connection name as the organization
110110
type: string
111111
server:
112+
default: https://api.streamnative.cloud
112113
description: Server is the URL of the API server
113114
type: string
114115
required:
115116
- auth
116-
- server
117117
type: object
118118
status:
119119
description: StreamNativeCloudConnectionStatus defines the observed state

config/crd/bases/resource.streamnative.io_streamnativecloudconnections.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ spec:
109109
If not specified, the operator will use the connection name as the organization
110110
type: string
111111
server:
112+
default: https://api.streamnative.cloud
112113
description: Server is the URL of the API server
113114
type: string
114115
required:
115116
- auth
116-
- server
117117
type: object
118118
status:
119119
description: StreamNativeCloudConnectionStatus defines the observed state

pkg/streamnativecloud/api_connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *APIConnection) connect() error {
8383
ClientSecret: c.credentials.ClientSecret,
8484
TokenURL: config.TokenEndpoint,
8585
EndpointParams: url.Values{
86-
"audience": []string{c.config.Spec.Server},
86+
"audience": []string{c.config.Spec.GetServer()},
8787
},
8888
}
8989

@@ -101,7 +101,7 @@ func (c *APIConnection) Test(ctx context.Context) error {
101101
if c.client == nil {
102102
return fmt.Errorf("waiting for client")
103103
}
104-
req, err := http.NewRequestWithContext(ctx, "GET", c.config.Spec.Server+"/healthz", http.NoBody)
104+
req, err := http.NewRequestWithContext(ctx, "GET", c.config.Spec.GetServer()+"/healthz", http.NoBody)
105105
if err != nil {
106106
return err
107107
}
@@ -134,7 +134,7 @@ func (c *APIConnection) NeedsUpdate(
134134
if c.credentials == nil {
135135
return true
136136
}
137-
return c.config.Spec.Server != config.Spec.Server ||
137+
return c.config.Spec.GetServer() != config.Spec.GetServer() ||
138138
c.credentials.ClientID != creds.ClientID ||
139139
c.credentials.ClientSecret != creds.ClientSecret ||
140140
c.credentials.IssuerURL != creds.IssuerURL

0 commit comments

Comments
 (0)