Skip to content

Commit

Permalink
Fix list filters
Browse files Browse the repository at this point in the history
  • Loading branch information
klapkov committed Jan 30, 2025
1 parent 5bbb0ed commit 7525e7a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
20 changes: 12 additions & 8 deletions api/payloads/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (c SecurityGroupCreate) ToMessage() repositories.CreateSecurityGroupMessage
type SecurityGroupList struct {
GUIDs string `json:"guids"`
Names string `json:"names"`
GloballyEnabledStaging bool `json:"globally_enabled_staging"`
GloballyEnabledRunning bool `json:"globally_enabled_running"`
GloballyEnabledStaging *bool `json:"globally_enabled_staging"`
GloballyEnabledRunning *bool `json:"globally_enabled_running"`
RunningSpaceGUIDs string `json:"running_space_guids"`
StagingSpaceGUIDs string `json:"staging_space_guids"`
}
Expand All @@ -72,12 +72,16 @@ func (l *SecurityGroupList) DecodeFromURLValues(values url.Values) error {

l.GUIDs = values.Get("guids")
l.Names = values.Get("names")
if l.GloballyEnabledStaging, err = getBool(values, "globally_enabled_staging"); err != nil {
return err
globallyEnabledStaging, err := parseBool(values.Get("globally_enabled_staging"))
if err != nil {
return fmt.Errorf("failed to parse 'globally_enabled_staging' query parameter: %w", err)
}
if l.GloballyEnabledRunning, err = getBool(values, "globally_enabled_running"); err != nil {
return err
globallyEnabledRunning, err := parseBool(values.Get("globally_enabled_running"))
if err != nil {
return fmt.Errorf("failed to parse 'globally_enabled_running' query parameter: %w", err)
}
l.GloballyEnabledStaging = globallyEnabledStaging
l.GloballyEnabledRunning = globallyEnabledRunning
l.RunningSpaceGUIDs = values.Get("running_space_guids")
l.StagingSpaceGUIDs = values.Get("staging_space_guids")

Expand All @@ -88,8 +92,8 @@ func (l SecurityGroupList) ToMessage() repositories.ListSecurityGroupMessage {
return repositories.ListSecurityGroupMessage{
GUIDs: parse.ArrayParam(l.GUIDs),
Names: parse.ArrayParam(l.Names),
GloballyEnabledStaging: &l.GloballyEnabledStaging,
GloballyEnabledRunning: &l.GloballyEnabledRunning,
GloballyEnabledStaging: l.GloballyEnabledStaging,
GloballyEnabledRunning: l.GloballyEnabledRunning,
RunningSpaceGUIDs: parse.ArrayParam(l.RunningSpaceGUIDs),
StagingSpaceGUIDs: parse.ArrayParam(l.StagingSpaceGUIDs),
}
Expand Down
25 changes: 19 additions & 6 deletions api/presenter/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
const securityGroupBase = "/v3/security_groups"

type SecurityGroupResponse struct {
GUID string `json:"guid"`
CreatedAt string `json:"created_at"`
Name string `json:"name"`
GloballyEnabled korifiv1alpha1.GloballyEnabled `json;"globally_enabled"`
Rules []korifiv1alpha1.SecurityGroupRule `json:"rules"`
Links SecurityGroupLinks `json:"links"`
GUID string `json:"guid"`
CreatedAt string `json:"created_at"`
Name string `json:"name"`
GloballyEnabled korifiv1alpha1.GloballyEnabled `json:"globally_enabled"`
Rules []korifiv1alpha1.SecurityGroupRule `json:"rules"`
Relationships payloads.SecurityGroupRelationships `json:"relationships"`
Links SecurityGroupLinks `json:"links"`
}

type SecurityGroupRunningSpacesResponse struct {
Expand All @@ -38,6 +39,18 @@ func ForSecurityGroup(securityGroupRecord repositories.SecurityGroupRecord, base
Name: securityGroupRecord.Name,
GloballyEnabled: securityGroupRecord.GloballyEnabled,
Rules: securityGroupRecord.Rules,
Relationships: payloads.SecurityGroupRelationships{
RunningSpaces: payloads.ToManyRelationship{
Data: slices.Collect(it.Map(slices.Values(securityGroupRecord.RunningSpaces), func(v string) payloads.RelationshipData {
return payloads.RelationshipData{GUID: v}
})),
},
StagingSpaces: payloads.ToManyRelationship{
Data: slices.Collect(it.Map(slices.Values(securityGroupRecord.StagingSpaces), func(v string) payloads.RelationshipData {
return payloads.RelationshipData{GUID: v}
})),
},
},
Links: SecurityGroupLinks{
Self: Link{
HRef: buildURL(baseURL).appendPath(securityGroupBase, securityGroupRecord.GUID).build(),
Expand Down
9 changes: 0 additions & 9 deletions api/repositories/security_group_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package repositories
import (
"context"
"fmt"
"log"
"slices"
"time"

Expand Down Expand Up @@ -60,10 +59,6 @@ type ListSecurityGroupMessage struct {
}

func (m *ListSecurityGroupMessage) matches(cfSecurityGroup korifiv1alpha1.CFSecurityGroup) bool {
log.Printf("guids: %+v", tools.EmptyOrContains(m.GUIDs, cfSecurityGroup.Name))
log.Printf("names: %+v", tools.EmptyOrContains(m.Names, cfSecurityGroup.Spec.DisplayName))
log.Printf("names: %+v", tools.EmptyOrContainsAllOf(m.RunningSpaceGUIDs, cfSecurityGroup.Spec.RunningSpaces))

return tools.EmptyOrContains(m.GUIDs, cfSecurityGroup.Name) &&
tools.EmptyOrContains(m.Names, cfSecurityGroup.Spec.DisplayName) &&
tools.NilOrEquals(m.GloballyEnabledStaging, cfSecurityGroup.Spec.GloballyEnabled.Staging) &&
Expand Down Expand Up @@ -213,11 +208,7 @@ func (r *SecurityGroupRepo) ListSecurityGroups(ctx context.Context, authInfo aut
return []SecurityGroupRecord{}, apierrors.FromK8sError(err, SecurityGroupResourceType)
}

log.Printf("before filtering: %+v", securityGroupList)
log.Printf("message: %+v", message)
filteredSecurityGroups := itx.FromSlice(securityGroupList.Items).Filter(message.matches)
asa := slices.Collect(it.Map(filteredSecurityGroups, toSecurityGroupRecord))
log.Printf("after filtering: %+v", asa)
return slices.Collect(it.Map(filteredSecurityGroups, toSecurityGroupRecord)), nil
}

Expand Down
3 changes: 0 additions & 3 deletions kpack-image-builder/controllers/buildworkload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
ss "log"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -690,8 +689,6 @@ func (r *BuildWorkloadReconciler) reconcileKpackImage(
korifiv1alpha1.CFWorkloadTypeLabelkey: korifiv1alpha1.CFWorkloadTypeBuild,
}

ss.Printf("staging labels: %+v", desiredKpackImage.Labels)

desiredKpackImage.Spec = buildv1alpha2.ImageSpec{
Tag: kpackImageTag,
Builder: corev1.ObjectReference{
Expand Down
3 changes: 0 additions & 3 deletions statefulset-runner/controllers/appworkload_to_stset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
ss "log"
"regexp"
"slices"
"sort"
Expand Down Expand Up @@ -191,8 +190,6 @@ func (r *AppWorkloadToStatefulsetConverter) Convert(appWorkload *korifiv1alpha1.
korifiv1alpha1.CFWorkloadTypeLabelkey: korifiv1alpha1.CFWorkloadTypeApp,
}

ss.Printf("app labels: %+v", labels)

statefulSet.Spec.Template.Labels = labels
statefulSet.Labels = labels

Expand Down

0 comments on commit 7525e7a

Please sign in to comment.