Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach Agent Pool network security group to karpenter node nics.. #610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/operator/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (o *Options) Parse(fs *coreoptions.FlagSet, args ...string) error {
}

// ClusterID is generated from cluster endpoint
o.ClusterID = getAKSClusterID(o.GetAPIServerName())
o.ClusterID = getAKSClusterID(o.ClusterName)
Copy link
Collaborator

@Bryce-Soghigian Bryce-Soghigian Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work? This changes the GetAPIServerName to use ClusterName, is that the same for private + public cluster? I thought CLUSTER_ENDPOINT will change depending on the cluster type, havent dug super deep into this option though.That is required by me for thorough review.

How is clusterID used in our codebase? Is there wider usage in our bootstrapping configuration?


return nil
}
Expand All @@ -153,7 +153,7 @@ func FromContext(ctx context.Context) *Options {
// The logic comes from AgentBaker and other places, originally from aks-engine
// with the additional assumption of DNS prefix being the first 33 chars of FQDN
func getAKSClusterID(apiServerFQDN string) string {
dnsPrefix := apiServerFQDN[:33]
dnsPrefix := apiServerFQDN
h := fnv.New64a()
h.Write([]byte(dnsPrefix))
r := rand.New(rand.NewSource(int64(h.Sum64()))) //nolint:gosec
Expand Down
34 changes: 22 additions & 12 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@
if err := opts.InstanceType.Requirements.Compatible(skuAcceleratedNetworkingRequirements); err == nil {
enableAcceleratedNetworking = true
}

sgId := opts.NetworkSecurityGroupID

Check failure on line 240 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / ci

ST1003: var sgId should be sgID (stylecheck)

networkSecurityGroup := armnetwork.SecurityGroup{
ID: &sgId,
}

nic := armnetwork.Interface{
Location: lo.ToPtr(p.location),
Properties: &armnetwork.InterfacePropertiesFormat{
Expand All @@ -250,6 +257,7 @@
},
},
},
NetworkSecurityGroup: &networkSecurityGroup,
EnableAcceleratedNetworking: lo.ToPtr(enableAcceleratedNetworking),
EnableIPForwarding: lo.ToPtr(false),
},
Expand Down Expand Up @@ -280,12 +288,13 @@
}

type createNICOptions struct {
NICName string
BackendPools *loadbalancer.BackendAddressPools
InstanceType *corecloudprovider.InstanceType
LaunchTemplate *launchtemplate.Template
NetworkPlugin string
NetworkPluginMode string
NICName string
BackendPools *loadbalancer.BackendAddressPools
InstanceType *corecloudprovider.InstanceType
LaunchTemplate *launchtemplate.Template
NetworkPlugin string
NetworkPluginMode string
NetworkSecurityGroupID string
}

func (p *DefaultProvider) createNetworkInterface(ctx context.Context, opts *createNICOptions) (string, error) {
Expand Down Expand Up @@ -457,12 +466,13 @@
}
nicReference, err := p.createNetworkInterface(ctx,
&createNICOptions{
NICName: resourceName,
NetworkPlugin: options.FromContext(ctx).NetworkPlugin,
NetworkPluginMode: options.FromContext(ctx).NetworkPluginMode,
LaunchTemplate: launchTemplate,
BackendPools: backendPools,
InstanceType: instanceType,
NICName: resourceName,
NetworkPlugin: options.FromContext(ctx).NetworkPlugin,
NetworkPluginMode: options.FromContext(ctx).NetworkPluginMode,
LaunchTemplate: launchTemplate,
BackendPools: backendPools,
InstanceType: instanceType,
NetworkSecurityGroupID: fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkSecurityGroups/aks-agentpool-%s-nsg", p.subscriptionID, p.resourceGroup, options.FromContext(ctx).ClusterID),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pull ClusterID into NicCreateOptions?

},
)
if err != nil {
Expand Down
Loading