Example #1
0
func StartHostLabelSync(interval int, kClient *kubernetesclient.Client) error {
	metadataClient, err := metadata.NewClientAndWait(metadataURL)
	if err != nil {
		log.Errorf("Error initializing metadata client: [%v]", err)
		return err
	}
	expiringCache := cache.New(cacheExpiryMinutes, 1*time.Minute)
	h := &hostLabelSyncer{
		kClient:        kClient,
		metadataClient: metadataClient,
		cache:          expiringCache,
	}
	metadataClient.OnChange(interval, h.syncHostLabels)
	return nil
}
Example #2
0
func NewMetadataClient() (*MetadataClient, error) {
	m, err := metadata.NewClientAndWait(metadataUrl)
	if err != nil {
		logrus.Fatalf("Failed to configure rancher-metadata: %v", err)
	}
	selfStack, err := m.GetSelfStack()
	if err != nil {
		logrus.Fatalf("Error reading stack info: %v", err)
	}

	return &MetadataClient{
		MetadataClient:  m,
		EnvironmentName: selfStack.EnvironmentName,
	}, nil
}
Example #3
0
func getServiceMetadata() map[string]interface{} {
	serviceMetadata := map[string]interface{}{}
	md, err := metadata.NewClientAndWait(metadataURL + "/2015-07-25")
	if err != nil {
		logrus.Fatalf("Can not load configuration from metadata")
	}

	serviceData, err := md.GetSelfService()
	if err != nil {
		logrus.Errorf("%s", err)
	}

	serviceMetadata = serviceData.Metadata

	return serviceMetadata
}
Example #4
0
func NewMetadataClient() (*MetadataClient, error) {
	m, err := metadata.NewClientAndWait(metadataUrl)
	if err != nil {
		logrus.Fatalf("Failed to configure rancher-metadata: %v", err)
	}

	envName, envUUID, err := getEnvironment(m)
	if err != nil {
		logrus.Fatalf("Error reading stack info: %v", err)
	}

	return &MetadataClient{
		MetadataClient:  m,
		EnvironmentName: envName,
		EnvironmentUUID: envUUID,
	}, nil
}
Example #5
0
func processTemplates(cnf *config.Config) error {

	apiURL := cnf.Host + cnf.Prefix
	meta, err := metadata.NewClientAndWait(apiURL)
	if err != nil {
		return errors.Annotate(err, "get meta client")
	}

	logging.Info("connect rancher metadata url: %q", apiURL)

	//expand template paths
	logging.Debug("expand template paths")
	for idx, set := range cnf.Sets {
		if !path.IsAbs(set.TemplatePath) {
			cnf.Sets[idx].TemplatePath = path.Join(DEFAULT_TEMPLATE_DIR, set.TemplatePath)
		}
	}

	version := "init"
	for {
		newVersion, err := meta.GetVersion()
		if err != nil {
			return errors.Annotate(err, "get version")
		}

		if newVersion == version {
			time.Sleep(5 * time.Second)
			continue
		}

		version = newVersion
		logging.Info("metadata changed - refresh config")

		for _, set := range cnf.Sets {
			scratch.Reset()
			if err := processTemplateSet(meta, set); err != nil {
				return errors.Annotate(err, "process template set")
			}
		}

		time.Sleep(time.Duration(cnf.Repeat) * time.Second)
	}

	return nil
}
Example #6
0
func appAction(cli *cli.Context) {
	client, err := metadata.NewClientAndWait(metadataUrl)
	if err != nil {
		logrus.Fatal(err)
	}

	w := election.New(client, cli.Int(port), cli.Args())

	if cli.Bool(check) {
		if w.IsLeader() {
			os.Exit(0)
		} else {
			os.Exit(1)
		}
	}

	if err := w.Watch(); err != nil {
		logrus.Fatal(err)
	}
}
Example #7
0
func NewReplicaStatus() (*ReplicaStatus, error) {
	metadata, err := md.NewClientAndWait(controller.MetadataURL)
	if err != nil {
		return nil, err
	}
	self, err := metadata.GetSelfContainer()
	if err != nil {
		return nil, err
	}
	addr := controller.ReplicaAddress(self.PrimaryIp, 9502)

	controllerClient := client.NewControllerClient("http://controller:9501/v1")
	replicaClient, err := replicaClient.NewReplicaClient("http://localhost:9502/v1")
	if err != nil {
		return nil, err
	}

	return &ReplicaStatus{
		controller: controllerClient,
		replica:    replicaClient,
		address:    addr,
	}, nil
}
func NewRancherClient(endpoint string) (*metadata.Client, error) {
	return metadata.NewClientAndWait(endpoint)
}