diff --git a/cmd/cl-adm/cmd/create/create_peer.go b/cmd/cl-adm/cmd/create/create_peer.go index 7a5ae9e7f..7550a7042 100644 --- a/cmd/cl-adm/cmd/create/create_peer.go +++ b/cmd/cl-adm/cmd/create/create_peer.go @@ -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.") } diff --git a/cmd/cl-adm/cmd/deploy/deploy_peer.go b/cmd/cl-adm/cmd/deploy/deploy_peer.go index d43f5ecb2..3474b8c08 100644 --- a/cmd/cl-adm/cmd/deploy/deploy_peer.go +++ b/cmd/cl-adm/cmd/deploy/deploy_peer.go @@ -16,6 +16,7 @@ package deploy import ( "context" "fmt" + "io/ioutil" "os" "path" "strings" @@ -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. @@ -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. @@ -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 @@ -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) + fmt.Println(managerModified) + err = decoder.DecodeEach(context.Background(), strings.NewReader(managerModified), decoder.CreateHandler(resource)) + if err != nil { return err } @@ -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") @@ -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)) diff --git a/cmd/cl-adm/config/config.go b/cmd/cl-adm/config/config.go index b5e0192ea..ee2c9fd7e 100644 --- a/cmd/cl-adm/config/config.go +++ b/cmd/cl-adm/config/config.go @@ -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. diff --git a/config/operator/manager/manager.yaml b/config/operator/manager/manager.yaml index 68d9c2dc7..cede66893 100644 --- a/config/operator/manager/manager.yaml +++ b/config/operator/manager/manager.yaml @@ -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: