chore: cleanup wrapper functions

This commit is contained in:
Julian Sommer
2026-06-26 10:47:19 +10:00
parent eda5987e0b
commit 54d2c8f250
7 changed files with 11 additions and 34 deletions
+1 -6
View File
@@ -134,7 +134,7 @@ func (reg *Registry) GetManifest(account, repo, ref string, acceptedTypes []stri
}
return nil, "", "", err
}
if len(acceptedTypes) > 0 && !mediaTypeAccepted(acceptedTypes, meta.MediaType) {
if len(acceptedTypes) > 0 && !slices.Contains(acceptedTypes, meta.MediaType) {
return nil, "", "", ErrImageNotFound
}
out, err := scoped.Store.GetObject(&s3.GetObjectInput{
@@ -326,8 +326,3 @@ func (reg *Registry) referencedDigests(account string) (map[string]bool, error)
}
return referenced, nil
}
// mediaTypeAccepted reports whether mediaType is in the accepted set.
func mediaTypeAccepted(accepted []string, mediaType string) bool {
return slices.Contains(accepted, mediaType)
}
+1 -5
View File
@@ -103,7 +103,7 @@ func (m *ExternalIPAM) AllocateIP(region, az, purpose, allocID, eniID, instanceI
if pool == nil {
return "", "", fmt.Errorf("InsufficientAddressCapacity: no external pool available for region=%q az=%q", region, az)
}
ip, err := m.allocateFromPool(pool.Name, purpose, allocID, eniID, instanceID)
ip, err := m.AllocateFromPool(pool.Name, purpose, allocID, eniID, instanceID)
if err != nil {
return "", "", err
}
@@ -112,10 +112,6 @@ func (m *ExternalIPAM) AllocateIP(region, az, purpose, allocID, eniID, instanceI
// AllocateFromPool allocates an IP from a specific named pool.
func (m *ExternalIPAM) AllocateFromPool(poolName, purpose, allocID, eniID, instanceID string) (string, error) {
return m.allocateFromPool(poolName, purpose, allocID, eniID, instanceID)
}
func (m *ExternalIPAM) allocateFromPool(poolName, purpose, allocID, eniID, instanceID string) (string, error) {
alloc, err := m.allocatorFor(poolName)
if err != nil {
return "", err
+2 -6
View File
@@ -230,15 +230,11 @@ func associatedPolicyToAWS(p AssociatedAccessPolicy) *eks.AssociatedAccessPolicy
}
}
// defaultKubernetesUsername mirrors AWS behaviour: username defaults to principalARN when omitted.
func defaultKubernetesUsername(principalARN string) string {
return principalARN
}
// newAccessEntryRecord builds a record; defaults username to principalARN when unset.
func newAccessEntryRecord(region, accountID, cluster, principalARN, username string, groups []string, entryType string, tags map[string]string, now time.Time) *AccessEntryRecord {
// AWS defaults the Kubernetes username to the principal ARN when omitted.
if username == "" {
username = defaultKubernetesUsername(principalARN)
username = principalARN
}
return &AccessEntryRecord{
ARN: AccessEntryARN(region, accountID, cluster, principalARN),
@@ -108,7 +108,7 @@ func (s *ELBv2ServiceImpl) SetSubnets(input *elbv2.SetSubnetsInput, accountID st
return nil, errors.New(awserrors.ErrorMissingParameter)
}
desired := desiredSubnetSet(input)
desired := flattenSubnetIDs(input.Subnets, input.SubnetMappings)
if len(desired) == 0 {
return nil, errors.New(awserrors.ErrorMissingParameter)
}
@@ -237,11 +237,6 @@ func (s *ELBv2ServiceImpl) SetSubnets(input *elbv2.SetSubnetsInput, accountID st
return s.setSubnetsOutput(lb), nil
}
// desiredSubnetSet flattens Subnets and SubnetMappings into a deduplicated, ordered list.
func desiredSubnetSet(input *elbv2.SetSubnetsInput) []string {
return flattenSubnetIDs(input.Subnets, input.SubnetMappings)
}
// flattenSubnetIDs deduplicates the explicit Subnets list and the SubnetMappings
// list into one ordered subnet-ID slice. LBC supplies ALB subnets via
// SubnetMappings, so both sources must be honoured wherever subnets are read.
+1 -1
View File
@@ -332,7 +332,7 @@ var instanceFamilyDefs = []instanceFamilyDef{
// System (internal-only, not exposed via DescribeInstanceTypes)
{name: "sys", sizes: systemSizes, currentGen: true},
// GPU Accelerated — not emitted by generateForGeneration; used by generateGPUTypes.
// GPU Accelerated — not emitted by generateForGeneration; used by GenerateGPUTypes.
{name: "g4dn", sizes: g4dnSizes, currentGen: true},
{name: "g4ad", sizes: g4adSizes, currentGen: true},
{name: "g5", sizes: g5Sizes, currentGen: true},
+1 -6
View File
@@ -113,12 +113,7 @@ func generateSystemTypes(arch string) map[string]*ec2.InstanceTypeInfo {
}
// GenerateGPUTypes returns InstanceTypeInfo entries for each GPU model with GpuInfo populated.
// Exported for use by the daemon's hot-reload path.
func GenerateGPUTypes(models []GPUModel, arch string) map[string]*ec2.InstanceTypeInfo {
return generateGPUTypes(models, arch)
}
func generateGPUTypes(models []GPUModel, arch string) map[string]*ec2.InstanceTypeInfo {
types := make(map[string]*ec2.InstanceTypeInfo)
seen := make(map[string]bool)
@@ -262,7 +257,7 @@ func DetectAndGenerate(cpu CPUInfo, arch string, gpuModels []GPUModel) map[strin
// Merge in GPU instance types if the host has recognized GPUs.
if len(gpuModels) > 0 {
maps.Copy(types, generateGPUTypes(gpuModels, arch))
maps.Copy(types, GenerateGPUTypes(gpuModels, arch))
}
if len(types) == 0 {
+4 -4
View File
@@ -423,7 +423,7 @@ func TestGPUModelForVendorDevice_Unknown(t *testing.T) {
}
func TestGenerateGPUTypes_NVIDIAa10g(t *testing.T) {
types := generateGPUTypes([]GPUModel{NVIDIAa10g}, "x86_64")
types := GenerateGPUTypes([]GPUModel{NVIDIAa10g}, "x86_64")
// g5 has 5 single-GPU sizes: xlarge, 2xlarge, 4xlarge, 8xlarge, 16xlarge
assert.Len(t, types, 5)
@@ -448,17 +448,17 @@ func TestGenerateGPUTypes_NVIDIAa10g(t *testing.T) {
func TestGenerateGPUTypes_DeduplicatesSameFamily(t *testing.T) {
// Two GPUs of the same model (same family) should produce only one set of types.
types := generateGPUTypes([]GPUModel{NVIDIAa10g, NVIDIAa10g}, "x86_64")
types := GenerateGPUTypes([]GPUModel{NVIDIAa10g, NVIDIAa10g}, "x86_64")
assert.Len(t, types, 5, "duplicate GPU model should not double the type count")
}
func TestGenerateGPUTypes_EmptyModels(t *testing.T) {
types := generateGPUTypes(nil, "x86_64")
types := GenerateGPUTypes(nil, "x86_64")
assert.Empty(t, types)
}
func TestIsGPUType(t *testing.T) {
gpuTypes := generateGPUTypes([]GPUModel{NVIDIAa10g}, "x86_64")
gpuTypes := GenerateGPUTypes([]GPUModel{NVIDIAa10g}, "x86_64")
for name, info := range gpuTypes {
assert.True(t, IsGPUType(info), "%s should be a GPU type", name)
}