Skip to content

Commit

Permalink
ci: Fix docgen by calling providers directly (#6138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored May 3, 2024
1 parent f6f1399 commit 35fe1c9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
34 changes: 27 additions & 7 deletions hack/docs/instancetypes_gen_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sort"
"strings"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -32,13 +33,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"

coreoperator "sigs.k8s.io/karpenter/pkg/operator"
coreoptions "sigs.k8s.io/karpenter/pkg/operator/options"
coretest "sigs.k8s.io/karpenter/pkg/test"

awscloudprovider "github.com/aws/karpenter-provider-aws/pkg/cloudprovider"
"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/aws/karpenter-provider-aws/pkg/operator"
"github.com/aws/karpenter-provider-aws/pkg/operator/options"
"github.com/aws/karpenter-provider-aws/pkg/test"
Expand Down Expand Up @@ -95,16 +96,35 @@ func main() {
Manager: &FakeManager{},
KubernetesInterface: kubernetes.NewForConfigOrDie(&rest.Config{}),
})
cp := awscloudprovider.New(op.InstanceTypesProvider, op.InstanceProvider,
op.EventRecorder, op.GetClient(), op.AMIProvider, op.SecurityGroupProvider, op.SubnetProvider)

if err := op.InstanceTypesProvider.UpdateInstanceTypes(ctx); err != nil {
log.Fatalf("updating instance types, %s", err)
}
if err := op.InstanceTypesProvider.UpdateInstanceTypeOfferings(ctx); err != nil {
log.Fatalf("updating instance types offerings, %s", err)
}
instanceTypes, err := cp.GetInstanceTypes(ctx, nil)
// Fake a NodeClass so we can use it to get InstanceTypes
nodeClass := &v1beta1.EC2NodeClass{
Spec: v1beta1.EC2NodeClassSpec{
SubnetSelectorTerms: []v1beta1.SubnetSelectorTerm{
{
Tags: map[string]string{
"*": "*",
},
},
},
},
}
subnets, err := op.SubnetProvider.List(ctx, nodeClass)
if err != nil {
log.Fatalf("listing subnets, %s", err)
}
nodeClass.Status.Subnets = lo.Map(subnets, func(ec2subnet *ec2.Subnet, _ int) v1beta1.Subnet {
return v1beta1.Subnet{
ID: *ec2subnet.SubnetId,
Zone: *ec2subnet.AvailabilityZone,
}
})
instanceTypes, err := op.InstanceTypesProvider.List(ctx, &corev1beta1.KubeletConfiguration{}, nodeClass)
if err != nil {
log.Fatalf("listing instance types, %s", err)
}
Expand Down Expand Up @@ -152,7 +172,7 @@ below are the resources available with some assumptions and after the instance o

// we don't want to show a few labels that will vary amongst regions
delete(labelNameMap, v1.LabelTopologyZone)
delete(labelNameMap, v1beta1.CapacityTypeLabelKey)
delete(labelNameMap, corev1beta1.CapacityTypeLabelKey)

labelNames := lo.Keys(labelNameMap)

Expand Down
3 changes: 0 additions & 3 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ func (c *CloudProvider) LivenessProbe(req *http.Request) error {

// GetInstanceTypes returns all available InstanceTypes
func (c *CloudProvider) GetInstanceTypes(ctx context.Context, nodePool *corev1beta1.NodePool) ([]*cloudprovider.InstanceType, error) {
if nodePool == nil {
return c.instanceTypeProvider.List(ctx, &corev1beta1.KubeletConfiguration{}, &v1beta1.EC2NodeClass{})
}
nodeClass, err := c.resolveNodeClassFromNodePool(ctx, nodePool)
if err != nil {
if errors.IsNotFound(err) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ func (p *DefaultProvider) List(ctx context.Context, kc *corev1beta1.KubeletConfi
if kc == nil {
kc = &corev1beta1.KubeletConfiguration{}
}
if nodeClass == nil {
nodeClass = &v1beta1.EC2NodeClass{}
}

if len(p.instanceTypesInfo) == 0 {
return nil, fmt.Errorf("no instance types found")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/instancetype/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func ENILimitedPods(ctx context.Context, info *ec2.InstanceTypeInfo) *resource.Q
// VPC CNI only uses the default network interface
// https://github.com/aws/amazon-vpc-cni-k8s/blob/3294231c0dce52cfe473bf6c62f47956a3b333b6/scripts/gen_vpc_ip_limits.go#L162
networkInterfaces := *info.NetworkInfo.NetworkCards[*info.NetworkInfo.DefaultNetworkCardIndex].MaximumNetworkInterfaces
usableNetworkInterfaces := lo.Max([]int64{(networkInterfaces - int64(options.FromContext(ctx).ReservedENIs)), 0})
usableNetworkInterfaces := lo.Max([]int64{networkInterfaces - int64(options.FromContext(ctx).ReservedENIs), 0})
if usableNetworkInterfaces == 0 {
return resource.NewQuantity(0, resource.DecimalSI)
}
Expand Down
40 changes: 20 additions & 20 deletions website/content/en/preview/reference/instance-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3174,8 +3174,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|238333Mi|
|pods|345|
|memory|237794Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
### `c6in.metal`
Expand All @@ -3200,8 +3200,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|238333Mi|
|pods|345|
|memory|237794Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
## c7a Family
Expand Down Expand Up @@ -11192,8 +11192,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|480816Mi|
|pods|345|
|memory|480277Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
### `m6idn.metal`
Expand All @@ -11219,8 +11219,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|480816Mi|
|pods|345|
|memory|480277Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
## m6in Family
Expand Down Expand Up @@ -11446,8 +11446,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|480816Mi|
|pods|345|
|memory|480277Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
### `m6in.metal`
Expand All @@ -11472,8 +11472,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|480816Mi|
|pods|345|
|memory|480277Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
## m7a Family
Expand Down Expand Up @@ -16231,8 +16231,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|965782Mi|
|pods|345|
|memory|965243Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
### `r6idn.metal`
Expand All @@ -16258,8 +16258,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|965782Mi|
|pods|345|
|memory|965243Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
## r6in Family
Expand Down Expand Up @@ -16485,8 +16485,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|965782Mi|
|pods|345|
|memory|965243Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
### `r6in.metal`
Expand All @@ -16511,8 +16511,8 @@ below are the resources available with some assumptions and after the instance o
|--|--|
|cpu|127610m|
|ephemeral-storage|17Gi|
|memory|965782Mi|
|pods|345|
|memory|965243Mi|
|pods|394|
|vpc.amazonaws.com/efa|2|
|vpc.amazonaws.com/pod-eni|108|
## r7a Family
Expand Down

0 comments on commit 35fe1c9

Please sign in to comment.