Skip to content

Commit

Permalink
formated ...go fmt ./...
Browse files Browse the repository at this point in the history
  • Loading branch information
sundaram2021 committed Nov 21, 2024
1 parent 422f613 commit 64d52a0
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 520 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
log.Err(err).Msg("Program failed for AWS")
os.Exit(1)
}

case "azure":
ctx, err = optionsAZURE.Parse(os.Args[2:])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion program/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ func NewSession(profile, region string, log zerolog.Logger) (*sessionInfo, error
} else {
return nil, err
}
}
}
2 changes: 1 addition & 1 deletion program/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ func (program *Options) WriteConfig(config *api.Config) error {
} else {
return err
}
}
}
2 changes: 1 addition & 1 deletion program/aws/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ func isTerminal(file *os.File) bool {
} else {
return (fileInfo.Mode() & os.ModeCharDevice) != 0
}
}
}
2 changes: 1 addition & 1 deletion program/aws/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ func (s *Stats) Log() {
Msg("Statistics")
}

var stats Stats
var stats Stats
2 changes: 1 addition & 1 deletion program/aws/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func (v *VersionCmd) Run(program *Options) error {
_ = program
_, _ = fmt.Println(Version)
return nil
}
}
210 changes: 105 additions & 105 deletions program/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,116 +60,116 @@ func (program *Options) getSubscriptions() <-chan string {
}

func (program *Options) getClustersFrom(s *azureSessionInfo, clusters chan<- AzureClusterInfo) {
var wg sync.WaitGroup
defer wg.Wait()

client := s.client
ctx := context.Background()
uniqueClusters := make(map[string]struct{})

pager := client.NewListPager(nil)

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
s.log.Error().Err(err).Msg("Error listing AKS clusters")
return
}

for _, c := range page.Value {
clusterKey := fmt.Sprintf("%s-%s", *c.Name, *c.Location)
if _, exists := uniqueClusters[clusterKey]; !exists {
uniqueClusters[clusterKey] = struct{}{}
stats.Clusters.Add(1)

wg.Add(1)
go func(c *armcontainerservice.ManagedCluster) {
defer wg.Done()

s.log.Debug().
Str("cluster_name", *c.Name).
Str("location", *c.Location).
Msg("Found unique AKS cluster")

clusters <- AzureClusterInfo{
ManagedCluster: c,
log: s.log.With().Str("cluster_name", *c.Name).Str("location", *c.Location).Logger(),
session: s,
}
}(c)
}
}
}
var wg sync.WaitGroup
defer wg.Wait()

client := s.client
ctx := context.Background()
uniqueClusters := make(map[string]struct{})

pager := client.NewListPager(nil)

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
s.log.Error().Err(err).Msg("Error listing AKS clusters")
return
}

for _, c := range page.Value {
clusterKey := fmt.Sprintf("%s-%s", *c.Name, *c.Location)
if _, exists := uniqueClusters[clusterKey]; !exists {
uniqueClusters[clusterKey] = struct{}{}
stats.Clusters.Add(1)

wg.Add(1)
go func(c *armcontainerservice.ManagedCluster) {
defer wg.Done()

s.log.Debug().
Str("cluster_name", *c.Name).
Str("location", *c.Location).
Msg("Found unique AKS cluster")

clusters <- AzureClusterInfo{
ManagedCluster: c,
log: s.log.With().Str("cluster_name", *c.Name).Str("location", *c.Location).Logger(),
session: s,
}
}(c)
}
}
}
}

func (program *Options) getUniqueAzureSessions() <-chan *azureSessionInfo {
sessions := make(chan *azureSessionInfo)

go func() {
wg := sync.WaitGroup{}
defer close(sessions)
defer wg.Wait()

subscriptions := make(map[string]bool)
for info := range program.getSubscriptionSessions() {
if _, found := subscriptions[info.subscription]; found {
info.log.Debug().Msg("Subscription is duplicate")
continue
}

stats.UniqueSubscriptions.Add(1)
info.log.Debug().Msg("Subscription is good for use")
subscriptions[info.subscription] = true
sessions <- info

for _, location := range program.Locations {
if location != info.location {
stats.Locations.Add(1)
wg.Add(1)
go func(subscription, location string) {
defer wg.Done()
log := log.With().Str("subscription", subscription).Str("location", location).Logger()
log.Debug().Msg("Creating regional session")

if s, err := program.newAzureSession(subscription, location); err == nil {
sessions <- s
} else {
log.Error().Err(err).Msg("Failed to create Azure session")
}
}(info.subscription, location)
}
}
}
}()

return sessions
sessions := make(chan *azureSessionInfo)

go func() {
wg := sync.WaitGroup{}
defer close(sessions)
defer wg.Wait()

subscriptions := make(map[string]bool)
for info := range program.getSubscriptionSessions() {
if _, found := subscriptions[info.subscription]; found {
info.log.Debug().Msg("Subscription is duplicate")
continue
}

stats.UniqueSubscriptions.Add(1)
info.log.Debug().Msg("Subscription is good for use")
subscriptions[info.subscription] = true
sessions <- info

for _, location := range program.Locations {
if location != info.location {
stats.Locations.Add(1)
wg.Add(1)
go func(subscription, location string) {
defer wg.Done()
log := log.With().Str("subscription", subscription).Str("location", location).Logger()
log.Debug().Msg("Creating regional session")

if s, err := program.newAzureSession(subscription, location); err == nil {
sessions <- s
} else {
log.Error().Err(err).Msg("Failed to create Azure session")
}
}(info.subscription, location)
}
}
}
}()

return sessions
}

func (program *Options) getSubscriptionSessions() <-chan *azureSessionInfo {
sessions := make(chan *azureSessionInfo)
wg := sync.WaitGroup{}

go func() {
defer close(sessions)
defer wg.Wait()

subscriptions := program.getSubscriptions()

for s := range subscriptions {
stats.Subscriptions.Add(1)
log := log.With().Str("subscription", s).Str("location", program.Locations[0]).Logger()
wg.Add(1)
go func(s string) {
defer wg.Done()
if session, err := NewAzureSession(s, program.Locations[0], log); err == nil {
stats.UsableSubscriptions.Add(1)
sessions <- session
}
}(s)
}
}()

return sessions
sessions := make(chan *azureSessionInfo)
wg := sync.WaitGroup{}

go func() {
defer close(sessions)
defer wg.Wait()

subscriptions := program.getSubscriptions()

for s := range subscriptions {
stats.Subscriptions.Add(1)
log := log.With().Str("subscription", s).Str("location", program.Locations[0]).Logger()
wg.Add(1)
go func(s string) {
defer wg.Done()
if session, err := NewAzureSession(s, program.Locations[0], log); err == nil {
stats.UsableSubscriptions.Add(1)
sessions <- session
}
}(s)
}
}()

return sessions
}

func (program *Options) newAzureSession(subscription, location string) (*azureSessionInfo, error) {
Expand Down Expand Up @@ -219,4 +219,4 @@ func NewAzureSession(subscription, location string, log zerolog.Logger) (*azureS
client: client,
log: log,
}, nil
}
}
2 changes: 1 addition & 1 deletion program/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func captureConfig(c AzureClusterInfo, resourceGroup string, i *api.Config) error {
certificateData := []byte(*c.ManagedCluster.Properties.NetworkProfile.ServiceCidr)
certificateData := []byte(*c.ManagedCluster.Properties.NetworkProfile.ServiceCidr)

cluster := api.Cluster{
Server: "https://" + *c.ManagedCluster.Properties.Fqdn,
Expand Down
Loading

0 comments on commit 64d52a0

Please sign in to comment.