Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/asset/installconfig/azure: create reusable session
This commit creates an Azure metadata struct in the installconfig asset (similar to AWS) and stores an Azure session and clients for interacting with the Azure API. This commit also refactors existing code to use this functionality rather than plumbing the install config values repeatedly.
- Loading branch information
1 parent
65b9ee9
commit cd3507b
Showing
16 changed files
with
133 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package azure | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
|
||
typesazure "github.com/openshift/installer/pkg/types/azure" | ||
) | ||
|
||
// Metadata holds additional metadata for InstallConfig resources that | ||
// does not need to be user-supplied (e.g. because it can be retrieved | ||
// from external APIs). | ||
type Metadata struct { | ||
session *Session | ||
client *Client | ||
dnsCfg *DNSConfig | ||
cloudName typesazure.CloudEnvironment | ||
|
||
mutex sync.Mutex | ||
} | ||
|
||
// NewMetadata initializes a new Metadata object. | ||
func NewMetadata(cloudName typesazure.CloudEnvironment) *Metadata { | ||
return &Metadata{cloudName: cloudName} | ||
} | ||
|
||
// Session holds an Azure session which can be used for Azure API calls | ||
// during asset generation. | ||
func (m *Metadata) Session() (*Session, error) { | ||
m.mutex.Lock() | ||
defer m.mutex.Unlock() | ||
|
||
return m.unlockedSession() | ||
} | ||
|
||
func (m *Metadata) unlockedSession() (*Session, error) { | ||
if m.session == nil { | ||
var err error | ||
m.session, err = GetSession(m.cloudName) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "creating Azure session") | ||
} | ||
} | ||
|
||
return m.session, nil | ||
} | ||
|
||
// Client holds an Azure Client that implements calls to the Azure API. | ||
func (m *Metadata) Client() (*Client, error) { | ||
if m.client == nil { | ||
ssn, err := m.Session() | ||
if err != nil { | ||
return nil, err | ||
} | ||
m.client = NewClient(ssn) | ||
} | ||
return m.client, nil | ||
} | ||
|
||
// DNSConfig holds an Azure DNSConfig Client that implements calls to the Azure API. | ||
func (m *Metadata) DNSConfig() (*DNSConfig, error) { | ||
if m.dnsCfg == nil { | ||
ssn, err := m.Session() | ||
if err != nil { | ||
return nil, err | ||
} | ||
m.dnsCfg = NewDNSConfig(ssn) | ||
} | ||
return m.dnsCfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.