Exemplo n.º 1
0
func createHeketiSecretFromDb(c *client.Client) (*kubeapi.Secret, error) {
	var dbfile bytes.Buffer

	// Save db
	err := c.BackupDb(&dbfile)
	if err != nil {
		return nil, fmt.Errorf("ERROR: %v\nUnable to get database from Heketi server", err.Error())
	}

	// Create Secret
	secret := &kubeapi.Secret{}
	secret.Kind = "Secret"
	secret.APIVersion = "v1"
	secret.ObjectMeta.Name = HeketiStorageSecretName
	secret.Data = make(map[string][]byte)
	secret.Data["heketi.db"] = dbfile.Bytes()

	return secret, nil
}
Exemplo n.º 2
0
func createHeketiStorageVolume(c *client.Client) (*api.VolumeInfoResponse, error) {

	// Make sure the volume does not already exist on any cluster
	clusters, err := c.ClusterList()
	if err != nil {
		return nil, err
	}

	// Go through all the clusters checking volumes
	for _, clusterId := range clusters.Clusters {
		cluster, err := c.ClusterInfo(clusterId)
		if err != nil {
			return nil, err
		}

		// Go through all the volumes checking the names
		for _, volumeId := range cluster.Volumes {
			volume, err := c.VolumeInfo(volumeId)
			if err != nil {
				return nil, err
			}

			// Check volume name
			if volume.Name == HeketiStorageVolumeName {
				return nil, fmt.Errorf("Volume %v alreay exists", HeketiStorageVolumeName)
			}
		}
	}

	// Create request
	req := &api.VolumeCreateRequest{}
	req.Size = HeketiStorageVolumeSize
	req.Durability.Type = api.DurabilityReplicate
	req.Durability.Replicate.Replica = 3
	req.Name = HeketiStorageVolumeName

	// Create volume
	volume, err := c.VolumeCreate(req)
	if err != nil {
		return nil, err
	}

	return volume, nil
}