Skip to content

Commit

Permalink
fix simulator bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 9, 2020
1 parent 6184351 commit 3aa5084
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions modules/agent/pkg/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/rancher/fleet/modules/agent/pkg/agent"
"github.com/rancher/fleet/modules/agent/pkg/register"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/config"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/name"
Expand All @@ -21,6 +20,10 @@ import (
"k8s.io/client-go/kubernetes"
)

var (
sem = semaphore.NewWeighted(50)
)

func Simulate(ctx context.Context, count int, kubeConfig, namespace, defaultNamespace string) error {
logrus.Infof("Starting %d simulators", count)

Expand All @@ -46,10 +49,6 @@ func Simulate(ctx context.Context, count int, kubeConfig, namespace, defaultName
return eg.Wait()
}

var (
sem = semaphore.NewWeighted(50)
)

func simulateAgent(ctx context.Context, i int, kubeConfig, namespace, defaultNamespace string) error {
simNamespace := fmt.Sprintf("%s%05d", namespace, i)
simDefaultNamespace := fmt.Sprintf("%s%05d", defaultNamespace, i)
Expand Down Expand Up @@ -85,15 +84,11 @@ func setupNamespace(ctx context.Context, kubeConfig, namespace, simNamespace str

clusterID := name.SafeConcatName(simNamespace, strings.SplitN(string(kubeSystem.UID), "-", 2)[0])

secret, err := k8s.CoreV1().Secrets(namespace).Get(ctx, register.CredName, metav1.GetOptions{})
secret, err := k8s.CoreV1().Secrets(namespace).Get(ctx, register.BootstrapCredName, metav1.GetOptions{})
if err != nil {
return "", err
}

if secret.Annotations[fleet.BootstrapToken] != "true" {
return "", fmt.Errorf("%s/%s does not have the label %s=true", namespace, register.CredName, fleet.BootstrapToken)
}

conf, err := k8s.CoreV1().ConfigMaps(namespace).Get(ctx, config.AgentConfigName, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
conf = nil
Expand All @@ -114,9 +109,6 @@ func setupNamespace(ctx context.Context, kubeConfig, namespace, simNamespace str
ObjectMeta: metav1.ObjectMeta{
Name: secret.Name,
Namespace: simNamespace,
Annotations: map[string]string{
fleet.BootstrapToken: "true",
},
},
Data: secret.Data,
}, metav1.CreateOptions{})
Expand Down

0 comments on commit 3aa5084

Please sign in to comment.