Skip to content

Commit

Permalink
operator: allow scoping internal admin API to specific nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Jun 13, 2022
1 parent e1bd2c4 commit 3e77ca2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/go/k8s/controllers/redpanda/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var _ = BeforeSuite(func(done Done) {
_ *redpandav1alpha1.Cluster,
_ string,
_ types.AdminTLSConfigProvider,
_ ...int32,
) (adminutils.AdminAPIClient, error) {
return testAdminAPI, nil
}
Expand Down Expand Up @@ -366,6 +367,10 @@ func (m *mockAdminAPI) SetUnavailable(unavailable bool) {
m.unavailable = unavailable
}

func (m *mockAdminAPI) GetNodeConfig() (admin.NodeConfig, error) {
return admin.NodeConfig{}, nil
}

func (m *mockAdminAPI) SetDirectValidationEnabled(directValidation bool) {
m.monitor.Lock()
defer m.monitor.Unlock()
Expand Down
22 changes: 17 additions & 5 deletions src/go/k8s/pkg/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewInternalAdminAPI(
redpandaCluster *redpandav1alpha1.Cluster,
fqdn string,
adminTLSProvider types.AdminTLSConfigProvider,
ordinals ...int32,
) (AdminAPIClient, error) {
adminInternal := redpandaCluster.AdminAPIInternal()
if adminInternal == nil {
Expand All @@ -53,11 +54,20 @@ func NewInternalAdminAPI(

adminInternalPort := adminInternal.Port

var urls []string
replicas := *redpandaCluster.Spec.Replicas
if len(ordinals) == 0 {
// Not a specific node, just go through all them
replicas := redpandaCluster.Status.CurrentReplicas
if replicas <= 0 {
replicas = *redpandaCluster.Spec.Replicas
}

for i := int32(0); i < replicas; i++ {
urls = append(urls, fmt.Sprintf("%s-%d.%s:%d", redpandaCluster.Name, i, fqdn, adminInternalPort))
for i := int32(0); i < replicas; i++ {
ordinals = append(ordinals, i)
}
}
var urls []string
for _, on := range ordinals {
urls = append(urls, fmt.Sprintf("%s-%d.%s:%d", redpandaCluster.Name, on, fqdn, adminInternalPort))
}

adminAPI, err := admin.NewAdminAPI(urls, admin.BasicCredentials{}, tlsConfig)
Expand All @@ -74,6 +84,7 @@ type AdminAPIClient interface {
ClusterConfigStatus(ctx context.Context) (admin.ConfigStatusResponse, error)
ClusterConfigSchema(ctx context.Context) (admin.ConfigSchema, error)
PatchClusterConfig(ctx context.Context, upsert map[string]interface{}, remove []string) (admin.ClusterConfigWriteResult, error)
GetNodeConfig(ctx context.Context) (admin.NodeConfig, error)

CreateUser(ctx context.Context, username, password, mechanism string) error

Expand All @@ -89,7 +100,8 @@ type AdminAPIClientFactory func(
k8sClient client.Reader,
redpandaCluster *redpandav1alpha1.Cluster,
fqdn string,
adminTLSProvider resources.AdminTLSConfigProvider,
adminTLSProvider types.AdminTLSConfigProvider,
ordinals ...int32,
) (AdminAPIClient, error)

var _ AdminAPIClientFactory = NewInternalAdminAPI

0 comments on commit 3e77ca2

Please sign in to comment.