Merge pull request #2750 from yousong/bugfix/yousong-lbagent-reuse-session

lbagent: 重用会话token
This commit is contained in:
yunion-ci-robot
2019-09-05 19:58:19 +08:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
+13 -2
View File
@@ -45,6 +45,8 @@ type ApiHelper struct {
haState string
haStateProvider HaStateProvider
mcclientSession *mcclient.ClientSession
}
func NewApiHelper(opts *Options) (*ApiHelper, error) {
@@ -103,10 +105,19 @@ func (h *ApiHelper) SetHaStateProvider(hsp HaStateProvider) {
}
func (h *ApiHelper) adminClientSession(ctx context.Context) *mcclient.ClientSession {
s := h.mcclientSession
if s != nil {
token := s.GetToken()
expires := token.GetExpires()
if time.Now().Add(time.Hour).After(expires) {
return s
}
}
region := h.opts.CommonOptions.Region
apiVersion := "v2"
s := auth.GetAdminSession(ctx, region, apiVersion)
return s
h.mcclientSession = auth.GetAdminSession(ctx, region, apiVersion)
return h.mcclientSession
}
func (h *ApiHelper) agentPeekOnce(ctx context.Context) (*models.LoadbalancerAgent, error) {
+4 -2
View File
@@ -74,7 +74,7 @@ func (b *LoadbalancerCorpus) GenHaproxyConfigs(dir string, opts *AgentParams) (*
}
for _, lbcert := range b.LoadbalancerCertificates {
d := []byte(lbcert.Certificate)
if d[len(d)-1] != '\n' {
if len(d) > 0 && d[len(d)-1] != '\n' {
d = append(d, '\n')
}
d = append(d, []byte(lbcert.PrivateKey)...)
@@ -154,7 +154,9 @@ func (b *LoadbalancerCorpus) GenHaproxyConfigs(dir string, opts *AgentParams) (*
r.LoadbalancersEnabled = append(r.LoadbalancersEnabled, lb)
d := buf.Bytes()
d = d[:len(d)-2]
if len(d) > 1 { // this is for sure because of "\n\n"
d = d[:len(d)-2]
}
fn := fmt.Sprintf("%s.%s", lb.Id, agentutils.HaproxyCfgExt)
p := filepath.Join(dir, fn)
err := ioutil.WriteFile(p, d, agentutils.FileModeFile)