Skip to content

Commit 3fa0cce

Browse files
authored
Merge pull request #1084 from gianlucam76/registry
Add registry option
2 parents be11e44 + ca59442 commit 3fa0cce

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

cmd/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var (
9393
disableCaching bool
9494
disableTelemetry bool
9595
autoDeployDependencies bool
96+
registry string
9697
)
9798

9899
const (
@@ -179,6 +180,7 @@ func main() {
179180
controllers.SetDriftdetectionConfigMap(driftDetectionConfigMap)
180181
controllers.SetLuaConfigMap(luaConfigMap)
181182
controllers.SetCAPIOnboardAnnotation(capiOnboardAnnotation)
183+
controllers.SetDriftDetectionRegistry(registry)
182184
// Start dependency manager
183185
dependencymanager.InitializeManagerInstance(ctx, mgr.GetClient(), autoDeployDependencies, ctrl.Log.WithName("dependency_manager"))
184186

@@ -258,6 +260,9 @@ func initFlags(fs *pflag.FlagSet) {
258260
"The name of the ConfigMap in the projectsveltos namespace containing lua utilities to be loaded."+
259261
"Changing the content of the ConfigMap does not cause Sveltos to redeploy.")
260262

263+
fs.StringVar(&registry, "registry", "",
264+
"Container registry for drift-detection images. Defaults to docker.io/ if empty.")
265+
261266
const defautlRestConfigQPS = 20
262267
fs.Float32Var(&restConfigQPS, "kube-api-qps", defautlRestConfigQPS,
263268
fmt.Sprintf("Maximum queries per second from the controller client to the Kubernetes API server. Defaults to %d",

controllers/management_cluster.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
driftdetectionConfigMap string
3232
luaConfigMap string
3333
capiOnboardAnnotation string
34+
driftDetectionRegistry string
3435
)
3536

3637
func SetManagementClusterAccess(c client.Client, config *rest.Config) {
@@ -70,6 +71,10 @@ func getCAPIOnboardAnnotation() string {
7071
return capiOnboardAnnotation
7172
}
7273

74+
func SetDriftDetectionRegistry(reg string) {
75+
driftDetectionRegistry = reg
76+
}
77+
7378
func collectDriftDetectionConfigMap(ctx context.Context) (*corev1.ConfigMap, error) {
7479
c := getManagementClusterClient()
7580
configMap := &corev1.ConfigMap{}
@@ -95,3 +100,7 @@ func collectLuaConfigMap(ctx context.Context) (*corev1.ConfigMap, error) {
95100

96101
return configMap, nil
97102
}
103+
104+
func getDriftDetectionRegistry() string {
105+
return driftDetectionRegistry
106+
}

controllers/resourcesummary.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,19 @@ func prepareDriftDetectionManagerYAML(driftDetectionManagerYAML, clusterNamespac
219219
driftDetectionManagerYAML =
220220
strings.ReplaceAll(driftDetectionManagerYAML, "v=5", "v=0")
221221

222+
registry := getDriftDetectionRegistry()
223+
if registry != "" {
224+
driftDetectionManagerYAML = replaceRegistry(driftDetectionManagerYAML, registry)
225+
}
226+
222227
return driftDetectionManagerYAML
223228
}
224229

230+
func replaceRegistry(agentYAML, registry string) string {
231+
oldRegistry := "docker.io"
232+
return strings.Replace(agentYAML, oldRegistry, registry, 1)
233+
}
234+
225235
// deployDriftDetectionManager deploys drift-detection-manager in the managed cluster
226236
func deployDriftDetectionManager(ctx context.Context, remoteRestConfig *rest.Config,
227237
clusterNamespace, clusterName, mode string, clusterType libsveltosv1beta1.ClusterType,

0 commit comments

Comments
 (0)