Skip to content

Commit

Permalink
cmd/deploy:Support container registry flad in deploy peer
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <[email protected]>
  • Loading branch information
kfirtoledo committed Mar 10, 2024
1 parent 52063c1 commit de6a933
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/cl-adm/cmd/create/create_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (o *PeerOptions) AddFlags(fs *pflag.FlagSet) {
"Type of dataplane, Supported values: \"envoy\" (default), \"go\"")
fs.StringVar(&o.LogLevel, "log-level", "info",
"The log level. One of fatal, error, warn, info, debug.")
fs.StringVar(&o.ContainerRegistry, "container-registry", "ghcr.io/clusterlink-net",
fs.StringVar(&o.ContainerRegistry, "container-registry", config.GhcrContainerRegistry,
"The container registry to pull the project images. If empty will use local registry.")
fs.BoolVar(&o.CRDMode, "crd-mode", false, "Run a CRD-based controlplane.")
}
Expand Down
33 changes: 23 additions & 10 deletions cmd/cl-adm/cmd/deploy/deploy_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package deploy
import (
"context"
"fmt"
"io/ioutil"

Check failure on line 19 in cmd/cl-adm/cmd/deploy/deploy_peer.go

View workflow job for this annotation

GitHub Actions / static-checks

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"os"
"path"
"strings"
Expand Down Expand Up @@ -46,6 +47,8 @@ type PeerOptions struct {
StartInstance bool
// Ingress, represents the type of service used to expose the ClusterLink deployment.
Ingress string
// ContainerRegistry is the container registry to pull the project images.
ContainerRegistry string
}

// NewCmdDeployPeer returns a cobra.Command to run the 'create peer' subcommand.
Expand Down Expand Up @@ -83,6 +86,8 @@ func (o *PeerOptions) AddFlags(fs *pflag.FlagSet) {
"Namespace where the ClusterLink components are deployed if --start is set.")
fs.StringVar(&o.Ingress, "start-ingress", string(apis.IngressTypeLoadBalancer),
"Represents the type of service used to expose the ClusterLink deployment (LoadBalancer/NodePort/none) if --start is set.")
fs.StringVar(&o.ContainerRegistry, "container-registry", config.GhcrContainerRegistry,
"The container registry to pull the project images.")
}

// RequiredFlags are the names of flags that must be explicitly specified.
Expand All @@ -93,8 +98,8 @@ func (o *PeerOptions) RequiredFlags() []string {
// Run the 'create peer' subcommand.
func (o *PeerOptions) Run() error {
peerDir := path.Join(o.CertDir, o.Name)
if err := o.verifyExists(peerDir); err != nil {
return err
if _, err := os.Stat(peerDir); err != nil {
return fmt.Errorf("failed to open certificates folder: %w", err)
}

// Create k8s resources
Expand All @@ -109,7 +114,21 @@ func (o *PeerOptions) Run() error {
}

// Create operator
if err := o.deployDir("operator/manager/*", resource); err != nil {
newImageName := path.Join(o.ContainerRegistry, "cl-operator:latest")
managerFile, err := configFiles.ConfigFiles.Open("operator/manager/manager.yaml")
if err != nil {
return err
}

managerBytes, err := ioutil.ReadAll(managerFile)
if err != nil {
return err
}

managerModified := strings.Replace(string(managerBytes), path.Join(config.GhcrContainerRegistry, "cl-operator:latest"), newImageName, -1)

Check failure on line 128 in cmd/cl-adm/cmd/deploy/deploy_peer.go

View workflow job for this annotation

GitHub Actions / static-checks

wrapperFunc: use strings.ReplaceAll method in `strings.Replace(string(managerBytes), path.Join<...>gistry, "cl-operator:latest"), newImageName, -1)` (gocritic)

Check failure on line 128 in cmd/cl-adm/cmd/deploy/deploy_peer.go

View workflow job for this annotation

GitHub Actions / static-checks

line is 138 characters (lll)
fmt.Println(managerModified)
err = decoder.DecodeEach(context.Background(), strings.NewReader(managerModified), decoder.CreateHandler(resource))
if err != nil {
return err
}

Expand Down Expand Up @@ -144,7 +163,7 @@ func (o *PeerOptions) Run() error {
Dataplanes: 1,
DataplaneType: platform.DataplaneTypeEnvoy,
LogLevel: "info",
ContainerRegistry: "ghcr.io/clusterlink-net", // Tell kind to use local image.
ContainerRegistry: o.ContainerRegistry,
Namespace: o.Namespace,
IngressType: o.Ingress,
}, "cl-instance")
Expand All @@ -161,12 +180,6 @@ func (o *PeerOptions) Run() error {
return nil
}

// verifyExists verifies a given path exist.
func (o *PeerOptions) verifyExists(dir string) error {
_, err := os.Stat(dir)
return err
}

// deployDir deploys K8s yaml from a directory.
func (o *PeerOptions) deployDir(dir string, resource *resources.Resources) error {
err := decoder.DecodeEachFile(context.Background(), configFiles.ConfigFiles, dir, decoder.CreateHandler(resource))
Expand Down
2 changes: 2 additions & 0 deletions cmd/cl-adm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
DataplaneDirectoryName = "dataplane"
// GWCTLDirectoryName is the directory name containing gwctl certificates.
GWCTLDirectoryName = "gwctl"
// GhcrContainerRegistry represents the remote container registry name on GitHub Container Registry.
GhcrContainerRegistry = "ghcr.io/clusterlink-net"
)

// FabricDirectory returns the base path of the fabric.
Expand Down
2 changes: 1 addition & 1 deletion config/operator/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
- --leader-elect
command:
- /cl-operator
image: cl-operator:latest
image: ghcr.io/clusterlink-net/cl-operator:latest
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
Expand Down

0 comments on commit de6a933

Please sign in to comment.