github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/common/unit.go (about)

     1  // Copyright 2020 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package common
     5  
     6  import (
     7  	"github.com/juju/names/v5"
     8  
     9  	"github.com/juju/juju/core/leadership"
    10  )
    11  
    12  // RevokeLeadershipFunc returns a function that revokes leadership for dead units.
    13  func RevokeLeadershipFunc(leadershipRevoker leadership.Revoker) func(names.Tag) {
    14  	return func(tag names.Tag) {
    15  		if tag.Kind() != names.UnitTagKind {
    16  			return
    17  		}
    18  		appName, _ := names.UnitApplication(tag.Id())
    19  		if err := leadershipRevoker.RevokeLeadership(appName, tag.Id()); err != nil && err != leadership.ErrClaimNotHeld {
    20  			logger.Warningf("cannot revoke lease for dead unit %q", tag.Id())
    21  		}
    22  	}
    23  }