-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for public IP scanning
- Loading branch information
aalexand
committed
Dec 18, 2024
1 parent
a2a44c5
commit 2d948ac
Showing
9 changed files
with
165 additions
and
1 deletion.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
package publicip | ||
|
||
import ( | ||
"context" | ||
registryv1 "github.com/adobe/cluster-registry/pkg/api/registry/v1" | ||
"github.com/go-logr/logr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type scanner struct { | ||
client client.Client | ||
logger logr.Logger | ||
namespace string | ||
} | ||
|
||
func (s *scanner) GetClient() client.Client { | ||
return s.client | ||
} | ||
|
||
func (s *scanner) Run(ctx context.Context) error { | ||
clusterList := ®istryv1.ClusterList{} | ||
err := s.client.List(context.TODO(), clusterList, &client.ListOptions{Namespace: s.namespace}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, cluster := range clusterList.Items { | ||
switch cluster.Spec.CloudType { | ||
case "aws", "eks": | ||
s.logger.Info("Querying AWS cloud provider API", "cluster", cluster.Name) | ||
|
||
case "azure", "aks": | ||
s.logger.Info("Querying Azure cloud provider API", "cluster", cluster.Name) | ||
|
||
case "datacenter": | ||
// not yet implemented | ||
s.logger.Info("Skipping datacenter cluster", "cluster", cluster.Name) | ||
|
||
default: | ||
s.logger.Info("Unknown cloud provider", "cluster", cluster.Name) | ||
} | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package publicip | ||
|
||
import ( | ||
"context" | ||
"github.com/go-logr/logr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
type Scanner interface { | ||
GetClient() client.Client | ||
Run(ctx context.Context) error | ||
} | ||
|
||
func NewScanner(opts ...Option) (Scanner, error) { | ||
options := Options{} | ||
for _, o := range opts { | ||
o(&options) | ||
} | ||
options, err := setDefaultOptions(options) | ||
if err != nil { | ||
options.Logger.Error(err, "failed to set defaults") | ||
return nil, err | ||
} | ||
|
||
return &scanner{ | ||
client: options.Client, | ||
logger: options.Logger, | ||
namespace: options.Namespace, | ||
}, nil | ||
} | ||
|
||
type Options struct { | ||
Logger logr.Logger | ||
Client client.Client | ||
Namespace string | ||
} | ||
|
||
type Option func(*Options) | ||
|
||
func setDefaultOptions(options Options) (Options, error) { | ||
if options.Logger.GetSink() == nil { | ||
options.Logger = log.Log.WithName("publicip-scanner") | ||
} | ||
|
||
return options, nil | ||
} |