Skip to content

Commit c94268a

Browse files
authored
adds creation of configmap for registry server config (#2558)
* adds creation of configmap for mcpregstry config Signed-off-by: ChrisJBurns <[email protected]> * clean Signed-off-by: ChrisJBurns <[email protected]> * adds git source int test Signed-off-by: ChrisJBurns <[email protected]> * corrects tests assertions Signed-off-by: ChrisJBurns <[email protected]> * changes some paths as a test Signed-off-by: ChrisJBurns <[email protected]> * adds emptyDir volume mount for temp storage Signed-off-by: ChrisJBurns <[email protected]> * refactor to reduce duplication Signed-off-by: ChrisJBurns <[email protected]> * lint Signed-off-by: ChrisJBurns <[email protected]> --------- Signed-off-by: ChrisJBurns <[email protected]>
1 parent 3d250ed commit c94268a

File tree

13 files changed

+928
-90
lines changed

13 files changed

+928
-90
lines changed

cmd/thv-operator/api/v1alpha1/mcpregistry_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ func (r *MCPRegistry) GetAPIResourceName() string {
405405
return fmt.Sprintf("%s-api", r.Name)
406406
}
407407

408+
// IsConfigMapRegistrySource returns true if the registry source is a configmap
409+
func (r *MCPRegistry) IsConfigMapRegistrySource() bool {
410+
return r.Spec.Source.Type == RegistrySourceTypeConfigMap
411+
}
412+
413+
// GetConfigMapSourceName returns the name of the configmap source
414+
// if its present, otherwise returns an empty string
415+
func (r *MCPRegistry) GetConfigMapSourceName() string {
416+
if !r.IsConfigMapRegistrySource() {
417+
return ""
418+
}
419+
420+
if r.Spec.Source.ConfigMap == nil {
421+
return ""
422+
}
423+
424+
return r.Spec.Source.ConfigMap.Name
425+
}
426+
408427
// DeriveOverallPhase determines the overall MCPRegistry phase based on sync and API status
409428
func (r *MCPRegistry) DeriveOverallPhase() MCPRegistryPhase {
410429
syncStatus := r.Status.SyncStatus

cmd/thv-operator/controllers/mcpregistry_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func getCurrentAttemptCount(mcpRegistry *mcpv1alpha1.MCPRegistry) int {
6060
func NewMCPRegistryReconciler(k8sClient client.Client, scheme *runtime.Scheme) *MCPRegistryReconciler {
6161
syncManager := sync.NewDefaultSyncManager(k8sClient, scheme)
6262
registryAPIManager := registryapi.NewManager(k8sClient, scheme)
63-
6463
return &MCPRegistryReconciler{
6564
Client: k8sClient,
6665
Scheme: scheme,

cmd/thv-operator/pkg/registryapi/config/config.go

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"fmt"
6+
"path/filepath"
67

78
"gopkg.in/yaml.v2"
89
corev1 "k8s.io/api/core/v1"
@@ -20,18 +21,20 @@ import (
2021
//
2122
//nolint:revive
2223
type ConfigManager interface {
23-
BuildConfig(mcpRegistry *mcpv1alpha1.MCPRegistry) (*Config, error)
24+
BuildConfig() (*Config, error)
2425
UpsertConfigMap(ctx context.Context,
2526
mcpRegistry *mcpv1alpha1.MCPRegistry,
2627
desired *corev1.ConfigMap,
2728
) error
29+
GetRegistryServerConfigMapName() string
2830
}
2931

3032
// NewConfigManager creates a new instance of ConfigManager with required dependencies
3133
func NewConfigManager(
3234
k8sClient client.Client,
3335
scheme *runtime.Scheme,
3436
checksumManager checksum.RunConfigConfigMapChecksum,
37+
mcpRegistry *mcpv1alpha1.MCPRegistry,
3538
) (ConfigManager, error) {
3639
if k8sClient == nil {
3740
return nil, fmt.Errorf("k8sClient is required and cannot be nil")
@@ -42,20 +45,33 @@ func NewConfigManager(
4245
if checksumManager == nil {
4346
return nil, fmt.Errorf("checksumManager is required and cannot be nil")
4447
}
45-
return &configManager{client: k8sClient, scheme: scheme, checksum: checksumManager}, nil
48+
49+
return &configManager{
50+
client: k8sClient,
51+
scheme: scheme,
52+
checksum: checksumManager,
53+
mcpRegistry: mcpRegistry,
54+
}, nil
4655
}
4756

4857
// NewConfigManagerForTesting creates a ConfigManager for testing purposes only.
4958
// WARNING: This manager will panic if methods requiring dependencies are called.
5059
// Only use this for testing BuildConfig or other methods that don't use k8s client.
51-
func NewConfigManagerForTesting() ConfigManager {
52-
return &configManager{}
60+
func NewConfigManagerForTesting(mcpRegistry *mcpv1alpha1.MCPRegistry) ConfigManager {
61+
return &configManager{
62+
mcpRegistry: mcpRegistry,
63+
}
5364
}
5465

5566
type configManager struct {
56-
client client.Client
57-
scheme *runtime.Scheme
58-
checksum checksum.RunConfigConfigMapChecksum
67+
client client.Client
68+
scheme *runtime.Scheme
69+
checksum checksum.RunConfigConfigMapChecksum
70+
mcpRegistry *mcpv1alpha1.MCPRegistry
71+
}
72+
73+
func (cm *configManager) GetRegistryServerConfigMapName() string {
74+
return fmt.Sprintf("%s-registry-server-config", cm.mcpRegistry.Name)
5975
}
6076

6177
const (
@@ -69,7 +85,16 @@ const (
6985
SourceTypeFile = "file"
7086

7187
// RegistryJSONFilePath is the file path where the registry JSON file will be mounted
72-
RegistryJSONFilePath = "/etc/registry/registry.json"
88+
RegistryJSONFilePath = "/config/registry"
89+
90+
// RegistryJSONFileName is the name of the registry JSON file
91+
RegistryJSONFileName = "registry.json"
92+
93+
// RegistryServerConfigFilePath is the file path where the registry server config file will be mounted
94+
RegistryServerConfigFilePath = "/config"
95+
96+
// RegistryServerConfigFileName is the name of the registry server config file
97+
RegistryServerConfigFileName = "config.yaml"
7398
)
7499

75100
// Config represents the root configuration structure
@@ -159,22 +184,24 @@ func (c *Config) ToConfigMapWithContentChecksum(mcpRegistry *mcpv1alpha1.MCPRegi
159184

160185
configMap := &corev1.ConfigMap{
161186
ObjectMeta: metav1.ObjectMeta{
162-
Name: fmt.Sprintf("%s-configmap", c.RegistryName),
187+
Name: fmt.Sprintf("%s-registry-server-config", c.RegistryName),
163188
Namespace: mcpRegistry.Namespace,
164189
Annotations: map[string]string{
165190
checksum.ContentChecksumAnnotation: ctrlutil.CalculateConfigHash(yamlData),
166191
},
167192
},
168193
Data: map[string]string{
169-
"config.yaml": string(yamlData),
194+
RegistryServerConfigFileName: string(yamlData),
170195
},
171196
}
172197
return configMap, nil
173198
}
174199

175-
func (*configManager) BuildConfig(mcpRegistry *mcpv1alpha1.MCPRegistry) (*Config, error) {
200+
func (cm *configManager) BuildConfig() (*Config, error) {
176201
config := Config{}
177202

203+
mcpRegistry := cm.mcpRegistry
204+
178205
if mcpRegistry.Name == "" {
179206
return nil, fmt.Errorf("registry name is required")
180207
}
@@ -254,7 +281,7 @@ func buildSourceConfig(source *mcpv1alpha1.MCPRegistrySource, config *Config) er
254281
// this stops the registry server worrying about configmap sources when all it has to do
255282
// is read the file on startup
256283
sourceConfig.File = &FileConfig{
257-
Path: RegistryJSONFilePath,
284+
Path: filepath.Join(RegistryJSONFilePath, RegistryJSONFileName),
258285
}
259286
sourceConfig.Type = SourceTypeFile
260287
case mcpv1alpha1.RegistrySourceTypeGit:

0 commit comments

Comments
 (0)