mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-24 23:19:39 -05:00
Read cdbg deploy IPs from ID file
This commit is contained in:
parent
a07e3bfaf4
commit
54319e4324
@ -2,9 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -17,7 +15,6 @@ import (
|
|||||||
configc "github.com/edgelesssys/constellation/internal/config"
|
configc "github.com/edgelesssys/constellation/internal/config"
|
||||||
"github.com/edgelesssys/constellation/internal/constants"
|
"github.com/edgelesssys/constellation/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/internal/file"
|
"github.com/edgelesssys/constellation/internal/file"
|
||||||
statec "github.com/edgelesssys/constellation/internal/state"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -70,26 +67,16 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, constellationConfig *c
|
|||||||
log.Println("WARN: constellation image does not look like a debug image. Are you using a debug image?")
|
log.Println("WARN: constellation image does not look like a debug image. Are you using a debug image?")
|
||||||
}
|
}
|
||||||
|
|
||||||
overrideIPs, err := cmd.Flags().GetStringSlice("ips")
|
ips, err := cmd.Flags().GetStringSlice("ips")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var ips []string
|
if len(ips) == 0 {
|
||||||
if len(overrideIPs) > 0 {
|
var idFile clusterIDsFile
|
||||||
ips = overrideIPs
|
if err := fileHandler.ReadJSON(constants.ClusterIDsFileName, &idFile); err != nil {
|
||||||
} else {
|
return fmt.Errorf("reading cluster IDs file: %w", err)
|
||||||
var stat statec.ConstellationState
|
|
||||||
err := fileHandler.ReadJSON(constants.StateFilename, &stat)
|
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
|
||||||
log.Println("Unable to load statefile. Maybe you forgot to run \"constellation create ...\" first?")
|
|
||||||
return fmt.Errorf("loading statefile: %w", err)
|
|
||||||
} else if err != nil {
|
|
||||||
return fmt.Errorf("loading statefile: %w", err)
|
|
||||||
}
|
|
||||||
ips, err = getIPsFromConfig(stat, *constellationConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
ips = []string{idFile.IP}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
@ -178,14 +165,6 @@ func deployOnEndpoint(ctx context.Context, in deployOnEndpointInput) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIPsFromConfig(stat statec.ConstellationState, config configc.Config) ([]string, error) {
|
|
||||||
if stat.LoadBalancerIP != "" {
|
|
||||||
return []string{stat.LoadBalancerIP}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("no load balancer IP found in statefile")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(deployCmd)
|
rootCmd.AddCommand(deployCmd)
|
||||||
|
|
||||||
@ -196,3 +175,9 @@ func init() {
|
|||||||
type fileToStreamReader interface {
|
type fileToStreamReader interface {
|
||||||
ReadStream(filename string, stream bootstrapper.WriteChunkStream, chunksize uint, showProgress bool) error
|
ReadStream(filename string, stream bootstrapper.WriteChunkStream, chunksize uint, showProgress bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type clusterIDsFile struct {
|
||||||
|
ClusterID string
|
||||||
|
OwnerID string
|
||||||
|
IP string
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user