mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
post tech review updates
This commit is contained in:
parent
1991475437
commit
0c87634bc3
5 changed files with 21 additions and 44 deletions
|
@ -56,29 +56,27 @@ func (service *Service) GetTunnelDetails(endpointID portainer.EndpointID) *porta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetActiveTunnel retrieves an active tunnel which allows communicating with edge agent
|
||||||
func (service *Service) GetActiveTunnel(endpoint *portainer.Endpoint) (*portainer.TunnelDetails, error) {
|
func (service *Service) GetActiveTunnel(endpoint *portainer.Endpoint) (*portainer.TunnelDetails, error) {
|
||||||
tunnel := service.GetTunnelDetails(endpoint.ID)
|
tunnel := service.GetTunnelDetails(endpoint.ID)
|
||||||
if tunnel.Status != portainer.EdgeAgentIdle {
|
if tunnel.Status == portainer.EdgeAgentIdle || tunnel.Status == portainer.EdgeAgentManagementRequired {
|
||||||
return tunnel, nil
|
err := service.SetTunnelStatusToRequired(endpoint.ID)
|
||||||
}
|
|
||||||
|
|
||||||
err := service.SetTunnelStatusToRequired(endpoint.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed opening tunnel to endpoint: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if endpoint.EdgeCheckinInterval == 0 {
|
|
||||||
settings, err := service.dataStore.Settings().Settings()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed fetching settings from db: %w", err)
|
return nil, fmt.Errorf("failed opening tunnel to endpoint: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint.EdgeCheckinInterval = settings.EdgeAgentCheckinInterval
|
if endpoint.EdgeCheckinInterval == 0 {
|
||||||
|
settings, err := service.dataStore.Settings().Settings()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed fetching settings from db: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint.EdgeCheckinInterval = settings.EdgeAgentCheckinInterval
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForAgentToConnect := time.Duration(endpoint.EdgeCheckinInterval) * time.Second
|
||||||
|
time.Sleep(waitForAgentToConnect * 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForAgentToConnect := time.Duration(endpoint.EdgeCheckinInterval) * time.Second
|
|
||||||
time.Sleep(waitForAgentToConnect * 2)
|
|
||||||
|
|
||||||
tunnel = service.GetTunnelDetails(endpoint.ID)
|
tunnel = service.GetTunnelDetails(endpoint.ID)
|
||||||
|
|
||||||
return tunnel, nil
|
return tunnel, nil
|
||||||
|
|
|
@ -95,24 +95,13 @@ func (deployer *KubernetesDeployer) Deploy(request *http.Request, endpoint *port
|
||||||
}
|
}
|
||||||
|
|
||||||
args := make([]string, 0)
|
args := make([]string, 0)
|
||||||
|
if endpoint.Type == portainer.AgentOnKubernetesEnvironment || endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment {
|
||||||
if endpoint.Type != portainer.KubernetesLocalEnvironment {
|
url, proxy, err := deployer.getAgentURL(endpoint)
|
||||||
url := endpoint.URL
|
if err != nil {
|
||||||
switch endpoint.Type {
|
return "", errors.WithMessage(err, "failed generating endpoint URL")
|
||||||
case portainer.AgentOnKubernetesEnvironment:
|
|
||||||
agentUrl, agentProxy, err := deployer.getAgentURL(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.WithMessage(err, "failed generating endpoint URL")
|
|
||||||
}
|
|
||||||
url = agentUrl
|
|
||||||
defer agentProxy.Close()
|
|
||||||
case portainer.EdgeAgentOnKubernetesEnvironment:
|
|
||||||
url, err = deployer.getEdgeUrl(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.WithMessage(err, "failed generating endpoint URL")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer proxy.Close()
|
||||||
args = append(args, "--server", url)
|
args = append(args, "--server", url)
|
||||||
args = append(args, "--insecure-skip-tls-verify")
|
args = append(args, "--insecure-skip-tls-verify")
|
||||||
}
|
}
|
||||||
|
@ -163,15 +152,6 @@ func (deployer *KubernetesDeployer) ConvertCompose(data []byte) ([]byte, error)
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (deployer *KubernetesDeployer) getEdgeUrl(endpoint *portainer.Endpoint) (string, error) {
|
|
||||||
tunnel, err := deployer.reverseTunnelService.GetActiveTunnel(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.Wrap(err, "failed activating tunnel")
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("http://127.0.0.1:%d/kubernetes", tunnel.Port), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (deployer *KubernetesDeployer) getAgentURL(endpoint *portainer.Endpoint) (string, *factory.ProxyServer, error) {
|
func (deployer *KubernetesDeployer) getAgentURL(endpoint *portainer.Endpoint) (string, *factory.ProxyServer, error) {
|
||||||
proxy, err := deployer.proxyManager.CreateAgentProxyServer(endpoint)
|
proxy, err := deployer.proxyManager.CreateAgentProxyServer(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -25,6 +25,7 @@ type stackDeployer struct {
|
||||||
kubernetesDeployer portainer.KubernetesDeployer
|
kubernetesDeployer portainer.KubernetesDeployer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewStackDeployer inits a stackDeployer struct with a SwarmStackManager, a ComposeStackManager and a KubernetesDeployer
|
||||||
func NewStackDeployer(swarmStackManager portainer.SwarmStackManager, composeStackManager portainer.ComposeStackManager, kubernetesDeployer portainer.KubernetesDeployer) *stackDeployer {
|
func NewStackDeployer(swarmStackManager portainer.SwarmStackManager, composeStackManager portainer.ComposeStackManager, kubernetesDeployer portainer.KubernetesDeployer) *stackDeployer {
|
||||||
return &stackDeployer{
|
return &stackDeployer{
|
||||||
lock: &sync.Mutex{},
|
lock: &sync.Mutex{},
|
||||||
|
|
|
@ -83,7 +83,6 @@ class KubernetesAppGitFormController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
console.log(this);
|
|
||||||
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
|
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
|
||||||
if (this.stack.GitConfig && this.stack.GitConfig.Authentication) {
|
if (this.stack.GitConfig && this.stack.GitConfig.Authentication) {
|
||||||
this.formValues.RepositoryUsername = this.stack.GitConfig.Authentication.Username;
|
this.formValues.RepositoryUsername = this.stack.GitConfig.Authentication.Username;
|
||||||
|
|
|
@ -112,7 +112,6 @@ class KubernetesRedeployAppGitFormController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
console.log(this);
|
|
||||||
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
|
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
|
||||||
// Init auto update
|
// Init auto update
|
||||||
if (this.stack.AutoUpdate && (this.stack.AutoUpdate.Interval || this.stack.AutoUpdate.Webhook)) {
|
if (this.stack.AutoUpdate && (this.stack.AutoUpdate.Interval || this.stack.AutoUpdate.Webhook)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue