post tech review updates

pull/5596/head
ArrisLee 2021-09-08 12:15:19 +12:00
parent 1991475437
commit 0c87634bc3
5 changed files with 21 additions and 44 deletions

View File

@ -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) {
tunnel := service.GetTunnelDetails(endpoint.ID)
if tunnel.Status != portainer.EdgeAgentIdle {
return tunnel, nil
}
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 tunnel.Status == portainer.EdgeAgentIdle || tunnel.Status == portainer.EdgeAgentManagementRequired {
err := service.SetTunnelStatusToRequired(endpoint.ID)
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)
return tunnel, nil

View File

@ -95,24 +95,13 @@ func (deployer *KubernetesDeployer) Deploy(request *http.Request, endpoint *port
}
args := make([]string, 0)
if endpoint.Type != portainer.KubernetesLocalEnvironment {
url := endpoint.URL
switch endpoint.Type {
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")
}
if endpoint.Type == portainer.AgentOnKubernetesEnvironment || endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment {
url, proxy, err := deployer.getAgentURL(endpoint)
if err != nil {
return "", errors.WithMessage(err, "failed generating endpoint URL")
}
defer proxy.Close()
args = append(args, "--server", url)
args = append(args, "--insecure-skip-tls-verify")
}
@ -163,15 +152,6 @@ func (deployer *KubernetesDeployer) ConvertCompose(data []byte) ([]byte, error)
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) {
proxy, err := deployer.proxyManager.CreateAgentProxyServer(endpoint)
if err != nil {

View File

@ -25,6 +25,7 @@ type stackDeployer struct {
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 {
return &stackDeployer{
lock: &sync.Mutex{},

View File

@ -83,7 +83,6 @@ class KubernetesAppGitFormController {
}
$onInit() {
console.log(this);
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
if (this.stack.GitConfig && this.stack.GitConfig.Authentication) {
this.formValues.RepositoryUsername = this.stack.GitConfig.Authentication.Username;

View File

@ -112,7 +112,6 @@ class KubernetesRedeployAppGitFormController {
}
$onInit() {
console.log(this);
this.formValues.RefName = this.stack.GitConfig.ReferenceName;
// Init auto update
if (this.stack.AutoUpdate && (this.stack.AutoUpdate.Interval || this.stack.AutoUpdate.Webhook)) {