Skip to content

Commit

Permalink
Clean up simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 24, 2020
1 parent 8912040 commit 129eb5f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion modules/agent/pkg/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func createClusterSecret(ctx context.Context, clusterID string, k8s corecontroll
systemNamespace := string(newSecret.Data[SystemNamespace])
deploymentNamespace := newSecret.Data[DeploymentNamespace]

if systemNamespace != secret.Namespace {
if !cfg.IgnoreAgentNamespaceCheck && systemNamespace != secret.Namespace {
return nil, fmt.Errorf("fleet-agent must be installed in the namespace %s", systemNamespace)
}

Expand Down
17 changes: 17 additions & 0 deletions modules/agent/pkg/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func setupNamespace(ctx context.Context, kubeConfig, namespace, simNamespace str
}

if conf != nil {
conf, err := injectConfig(conf)
if err != nil {
return "", err
}
_, err = k8s.CoreV1().ConfigMaps(simNamespace).Create(ctx, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: conf.Name,
Expand All @@ -133,3 +137,16 @@ func setupNamespace(ctx context.Context, kubeConfig, namespace, simNamespace str

return clusterID, agent.Register(ctx, kubeConfig, simNamespace, clusterID)
}

func injectConfig(cm *corev1.ConfigMap) (*corev1.ConfigMap, error) {
cfg, err := config.ReadConfig(cm)
if err != nil {
return nil, err
}
cfg.IgnoreAgentNamespaceCheck = true
if cfg.Labels == nil {
cfg.Labels = map[string]string{}
}
cfg.Labels["fleet.cattle.io/non-managed-agent"] = "true"
return config.ToConfigMap(cm.Namespace, cm.Name, cfg)
}
3 changes: 0 additions & 3 deletions package/Dockerfile.simulator

This file was deleted.

20 changes: 0 additions & 20 deletions package/simulator

This file was deleted.

1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Config struct {
GithubURLPrefix string `json:"githubURLPrefix,omitempty"`
WebhookReceiverURL string `json:"webhookReceiverURL,omitempty"`
IgnoreClusterRegistrationLabels bool `json:"ignoreClusterRegistrationLabels,omitempty"`
IgnoreAgentNamespaceCheck bool `json:"ignoreAgentNamespaceCheck,omitempty"`
}

type Bootstrap struct {
Expand Down
1 change: 0 additions & 1 deletion scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ done

build-image fleet
build-image fleet-agent .agent
build-image fleet-agent-simulator .simulator

./scripts/package-helm

0 comments on commit 129eb5f

Please sign in to comment.