From 77a0ab50ce22d13fdf732e653408c7954d3b4c74 Mon Sep 17 00:00:00 2001 From: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> Date: Tue, 27 Feb 2024 09:41:52 -0800 Subject: [PATCH] Add Missing Optional Annotation for Port (#288) * add optional label Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * add migration Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * fix merge conflictsg Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * fix lint Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> --------- Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> --- cmd/serve.go | 2 +- ...240214095509_change_port_name_optional.sql | 7 +++ db/migrations/atlas.sum | 3 +- internal/ent/generated/gql_mutation_input.go | 10 +++- internal/ent/generated/gql_where_input.go | 8 ++++ internal/ent/generated/migrate/schema.go | 2 +- internal/ent/generated/mutation.go | 19 ++++++++ internal/ent/generated/port/where.go | 10 ++++ internal/ent/generated/port_create.go | 11 +++-- internal/ent/generated/port_update.go | 34 +++++++++++++ internal/ent/schema/port.go | 3 +- internal/graphapi/gen_server.go | 48 ++++++++++++++----- internal/graphapi/loadbalancer_test.go | 2 +- internal/graphapi/port_test.go | 42 ++++++++++------ internal/graphclient/gen_client.go | 4 +- internal/graphclient/gen_models.go | 7 ++- internal/graphclient/schema/schema.graphql | 7 ++- pkg/client/client_test.go | 4 +- schema.graphql | 7 ++- schema/ent.graphql | 7 ++- x/pubsubinfo/gql_hooks.go | 8 ++-- 21 files changed, 192 insertions(+), 53 deletions(-) create mode 100644 db/migrations/20240214095509_change_port_name_optional.sql diff --git a/cmd/serve.go b/cmd/serve.go index 6e5415b1d..43c704010 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -50,7 +50,7 @@ var ( var serveCmd = &cobra.Command{ Use: "serve", Short: "Start the load balancer Graph API", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { if pidFileName != "" { if err := writePidFile(pidFileName); err != nil { logger.Error("failed to write pid file", zap.Error(err)) diff --git a/db/migrations/20240214095509_change_port_name_optional.sql b/db/migrations/20240214095509_change_port_name_optional.sql new file mode 100644 index 000000000..a40144984 --- /dev/null +++ b/db/migrations/20240214095509_change_port_name_optional.sql @@ -0,0 +1,7 @@ +-- +goose Up +-- modify "ports" table +ALTER TABLE "ports" ALTER COLUMN "name" DROP NOT NULL; + +-- +goose Down +-- reverse: modify "ports" table +ALTER TABLE "ports" ALTER COLUMN "name" SET NOT NULL; diff --git a/db/migrations/atlas.sum b/db/migrations/atlas.sum index 52ad1a97c..48ff390ad 100644 --- a/db/migrations/atlas.sum +++ b/db/migrations/atlas.sum @@ -1,7 +1,8 @@ -h1:0KtiTooJCnoUsSF1CYnlRKEVEQFmH2Fj55S/41WmJr8= +h1:MujJgh8ifO4DK4QeukfFWRsa5OFI9Q0agyQwNlkI/3Q= 20230503185445_initial-migration.sql h1:4pqNp2MDBBRdGxU/H5mmZui9oi1SyjIiMVGatajrBeY= 20230615194819_drop_tenant_add_owner.sql h1:KGCsItU0NYhxYEkhZOaMQjfIrBMnek5rxC6D/LhnyCk= 20230629085916_drop_status_and_annotations.sql h1:kvDMoaMEjyoj/aRi6rw4XvCLxGH09vGGLbL0/p5tpPo= 20231017005257_add_origin_weight.sql h1:NuorUbcydDqcyPK8wgwlkQxaH+zGWfVtJW9UPL1Vn+E= 20240207205734_audit-fields.sql h1:cplFCBB7laCP5Y+UAoxIfITMo56Hoc5XIVvgcfGL9o0= 20240208121103_softdelete.sql h1:rt3nHn/1KzxSAbJZ33fQJZi5emLk7Q2PCRcfxWUeveY= +20240214095509_change_port_name_optional.sql h1:ArlIsVK4Tgi6AW6NiRMbAqU43+5KFqDkaa+YmxSoBkE= diff --git a/internal/ent/generated/gql_mutation_input.go b/internal/ent/generated/gql_mutation_input.go index ede04cd8c..43c5ff969 100644 --- a/internal/ent/generated/gql_mutation_input.go +++ b/internal/ent/generated/gql_mutation_input.go @@ -236,7 +236,7 @@ func (c *PoolUpdateOne) SetInput(i UpdateLoadBalancerPoolInput) *PoolUpdateOne { // CreateLoadBalancerPortInput represents a mutation input for creating loadbalancerports. type CreateLoadBalancerPortInput struct { Number int - Name string + Name *string PoolIDs []gidx.PrefixedID LoadBalancerID gidx.PrefixedID } @@ -244,7 +244,9 @@ type CreateLoadBalancerPortInput struct { // Mutate applies the CreateLoadBalancerPortInput on the PortMutation builder. func (i *CreateLoadBalancerPortInput) Mutate(m *PortMutation) { m.SetNumber(i.Number) - m.SetName(i.Name) + if v := i.Name; v != nil { + m.SetName(*v) + } if v := i.PoolIDs; len(v) > 0 { m.AddPoolIDs(v...) } @@ -260,6 +262,7 @@ func (c *PortCreate) SetInput(i CreateLoadBalancerPortInput) *PortCreate { // UpdateLoadBalancerPortInput represents a mutation input for updating loadbalancerports. type UpdateLoadBalancerPortInput struct { Number *int + ClearName bool Name *string ClearPools bool AddPoolIDs []gidx.PrefixedID @@ -271,6 +274,9 @@ func (i *UpdateLoadBalancerPortInput) Mutate(m *PortMutation) { if v := i.Number; v != nil { m.SetNumber(*v) } + if i.ClearName { + m.ClearName() + } if v := i.Name; v != nil { m.SetName(*v) } diff --git a/internal/ent/generated/gql_where_input.go b/internal/ent/generated/gql_where_input.go index 4241d4125..92176e408 100644 --- a/internal/ent/generated/gql_where_input.go +++ b/internal/ent/generated/gql_where_input.go @@ -1834,6 +1834,8 @@ type LoadBalancerPortWhereInput struct { NameContains *string `json:"nameContains,omitempty"` NameHasPrefix *string `json:"nameHasPrefix,omitempty"` NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil bool `json:"nameIsNil,omitempty"` + NameNotNil bool `json:"nameNotNil,omitempty"` NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` @@ -2211,6 +2213,12 @@ func (i *LoadBalancerPortWhereInput) P() (predicate.Port, error) { if i.NameHasSuffix != nil { predicates = append(predicates, port.NameHasSuffix(*i.NameHasSuffix)) } + if i.NameIsNil { + predicates = append(predicates, port.NameIsNil()) + } + if i.NameNotNil { + predicates = append(predicates, port.NameNotNil()) + } if i.NameEqualFold != nil { predicates = append(predicates, port.NameEqualFold(*i.NameEqualFold)) } diff --git a/internal/ent/generated/migrate/schema.go b/internal/ent/generated/migrate/schema.go index 4bed3fde3..c616ecd81 100644 --- a/internal/ent/generated/migrate/schema.go +++ b/internal/ent/generated/migrate/schema.go @@ -170,7 +170,7 @@ var ( {Name: "created_by", Type: field.TypeString, Nullable: true}, {Name: "updated_by", Type: field.TypeString, Nullable: true}, {Name: "number", Type: field.TypeInt}, - {Name: "name", Type: field.TypeString}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "load_balancer_id", Type: field.TypeString}, } // PortsTable holds the schema information for the "ports" table. diff --git a/internal/ent/generated/mutation.go b/internal/ent/generated/mutation.go index a562f225e..781e9caee 100644 --- a/internal/ent/generated/mutation.go +++ b/internal/ent/generated/mutation.go @@ -3718,9 +3718,22 @@ func (m *PortMutation) OldName(ctx context.Context) (v string, err error) { return oldValue.Name, nil } +// ClearName clears the value of the "name" field. +func (m *PortMutation) ClearName() { + m.name = nil + m.clearedFields[port.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *PortMutation) NameCleared() bool { + _, ok := m.clearedFields[port.FieldName] + return ok +} + // ResetName resets all changes to the "name" field. func (m *PortMutation) ResetName() { m.name = nil + delete(m.clearedFields, port.FieldName) } // SetLoadBalancerID sets the "load_balancer_id" field. @@ -4084,6 +4097,9 @@ func (m *PortMutation) ClearedFields() []string { if m.FieldCleared(port.FieldUpdatedBy) { fields = append(fields, port.FieldUpdatedBy) } + if m.FieldCleared(port.FieldName) { + fields = append(fields, port.FieldName) + } return fields } @@ -4110,6 +4126,9 @@ func (m *PortMutation) ClearField(name string) error { case port.FieldUpdatedBy: m.ClearUpdatedBy() return nil + case port.FieldName: + m.ClearName() + return nil } return fmt.Errorf("unknown Port nullable field %s", name) } diff --git a/internal/ent/generated/port/where.go b/internal/ent/generated/port/where.go index eb85c3391..bd99ebf86 100644 --- a/internal/ent/generated/port/where.go +++ b/internal/ent/generated/port/where.go @@ -565,6 +565,16 @@ func NameHasSuffix(v string) predicate.Port { return predicate.Port(sql.FieldHasSuffix(FieldName, v)) } +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Port { + return predicate.Port(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Port { + return predicate.Port(sql.FieldNotNull(FieldName)) +} + // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Port { return predicate.Port(sql.FieldEqualFold(FieldName, v)) diff --git a/internal/ent/generated/port_create.go b/internal/ent/generated/port_create.go index b69b8c107..bc91bae08 100644 --- a/internal/ent/generated/port_create.go +++ b/internal/ent/generated/port_create.go @@ -133,6 +133,14 @@ func (pc *PortCreate) SetName(s string) *PortCreate { return pc } +// SetNillableName sets the "name" field if the given value is not nil. +func (pc *PortCreate) SetNillableName(s *string) *PortCreate { + if s != nil { + pc.SetName(*s) + } + return pc +} + // SetLoadBalancerID sets the "load_balancer_id" field. func (pc *PortCreate) SetLoadBalancerID(gi gidx.PrefixedID) *PortCreate { pc.mutation.SetLoadBalancerID(gi) @@ -250,9 +258,6 @@ func (pc *PortCreate) check() error { return &ValidationError{Name: "number", err: fmt.Errorf(`generated: validator failed for field "Port.number": %w`, err)} } } - if _, ok := pc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`generated: missing required field "Port.name"`)} - } if _, ok := pc.mutation.LoadBalancerID(); !ok { return &ValidationError{Name: "load_balancer_id", err: errors.New(`generated: missing required field "Port.load_balancer_id"`)} } diff --git a/internal/ent/generated/port_update.go b/internal/ent/generated/port_update.go index 67c059a4e..a673cf1fa 100644 --- a/internal/ent/generated/port_update.go +++ b/internal/ent/generated/port_update.go @@ -123,6 +123,20 @@ func (pu *PortUpdate) SetName(s string) *PortUpdate { return pu } +// SetNillableName sets the "name" field if the given value is not nil. +func (pu *PortUpdate) SetNillableName(s *string) *PortUpdate { + if s != nil { + pu.SetName(*s) + } + return pu +} + +// ClearName clears the value of the "name" field. +func (pu *PortUpdate) ClearName() *PortUpdate { + pu.mutation.ClearName() + return pu +} + // AddPoolIDs adds the "pools" edge to the Pool entity by IDs. func (pu *PortUpdate) AddPoolIDs(ids ...gidx.PrefixedID) *PortUpdate { pu.mutation.AddPoolIDs(ids...) @@ -264,6 +278,9 @@ func (pu *PortUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := pu.mutation.Name(); ok { _spec.SetField(port.FieldName, field.TypeString, value) } + if pu.mutation.NameCleared() { + _spec.ClearField(port.FieldName, field.TypeString) + } if pu.mutation.PoolsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -408,6 +425,20 @@ func (puo *PortUpdateOne) SetName(s string) *PortUpdateOne { return puo } +// SetNillableName sets the "name" field if the given value is not nil. +func (puo *PortUpdateOne) SetNillableName(s *string) *PortUpdateOne { + if s != nil { + puo.SetName(*s) + } + return puo +} + +// ClearName clears the value of the "name" field. +func (puo *PortUpdateOne) ClearName() *PortUpdateOne { + puo.mutation.ClearName() + return puo +} + // AddPoolIDs adds the "pools" edge to the Pool entity by IDs. func (puo *PortUpdateOne) AddPoolIDs(ids ...gidx.PrefixedID) *PortUpdateOne { puo.mutation.AddPoolIDs(ids...) @@ -579,6 +610,9 @@ func (puo *PortUpdateOne) sqlSave(ctx context.Context) (_node *Port, err error) if value, ok := puo.mutation.Name(); ok { _spec.SetField(port.FieldName, field.TypeString, value) } + if puo.mutation.NameCleared() { + _spec.ClearField(port.FieldName, field.TypeString) + } if puo.mutation.PoolsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/internal/ent/schema/port.go b/internal/ent/schema/port.go index e1696f55f..66fd5f280 100644 --- a/internal/ent/schema/port.go +++ b/internal/ent/schema/port.go @@ -54,7 +54,8 @@ func (Port) Fields() []ent.Field { field.String("name"). Annotations( entgql.OrderField("name"), - ), + ). + Optional(), field.String("load_balancer_id"). GoType(gidx.PrefixedID("")). Immutable(). diff --git a/internal/graphapi/gen_server.go b/internal/graphapi/gen_server.go index 02f6d35c5..b38140c45 100644 --- a/internal/graphapi/gen_server.go +++ b/internal/graphapi/gen_server.go @@ -1705,7 +1705,7 @@ Input was generated by ent. """ input CreateLoadBalancerPortInput { number: Int! - name: String! + name: String poolIDs: [ID!] loadBalancerID: ID! } @@ -2191,7 +2191,7 @@ type LoadBalancerPort implements Node @key(fields: "id") @prefixedID(prefix: "lo createdBy: String updatedBy: String number: Int! - name: String! + name: String loadBalancerID: ID! pools: [LoadBalancerPool!] loadBalancer: LoadBalancer! @@ -2345,6 +2345,8 @@ input LoadBalancerPortWhereInput { nameContains: String nameHasPrefix: String nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean nameEqualFold: String nameContainsFold: String """pools edge predicates""" @@ -2739,6 +2741,7 @@ Input was generated by ent. input UpdateLoadBalancerPortInput { number: Int name: String + clearName: Boolean addPoolIDs: [ID!] removePoolIDs: [ID!] clearPools: Boolean @@ -8253,14 +8256,11 @@ func (ec *executionContext) _LoadBalancerPort_name(ctx context.Context, field gr return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } res := resTmp.(string) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalOString2string(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_LoadBalancerPort_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -13911,7 +13911,7 @@ func (ec *executionContext) unmarshalInputCreateLoadBalancerPortInput(ctx contex var err error ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) - data, err := ec.unmarshalNString2string(ctx, v) + data, err := ec.unmarshalOString2áš–string(ctx, v) if err != nil { return it, err } @@ -16272,7 +16272,7 @@ func (ec *executionContext) unmarshalInputLoadBalancerPortWhereInput(ctx context asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "updatedAt", "updatedAtNEQ", "updatedAtIn", "updatedAtNotIn", "updatedAtGT", "updatedAtGTE", "updatedAtLT", "updatedAtLTE", "deletedAt", "deletedAtNEQ", "deletedAtIn", "deletedAtNotIn", "deletedAtGT", "deletedAtGTE", "deletedAtLT", "deletedAtLTE", "deletedAtIsNil", "deletedAtNotNil", "deletedBy", "deletedByNEQ", "deletedByIn", "deletedByNotIn", "deletedByGT", "deletedByGTE", "deletedByLT", "deletedByLTE", "deletedByContains", "deletedByHasPrefix", "deletedByHasSuffix", "deletedByIsNil", "deletedByNotNil", "deletedByEqualFold", "deletedByContainsFold", "createdBy", "createdByNEQ", "createdByIn", "createdByNotIn", "createdByGT", "createdByGTE", "createdByLT", "createdByLTE", "createdByContains", "createdByHasPrefix", "createdByHasSuffix", "createdByIsNil", "createdByNotNil", "createdByEqualFold", "createdByContainsFold", "updatedBy", "updatedByNEQ", "updatedByIn", "updatedByNotIn", "updatedByGT", "updatedByGTE", "updatedByLT", "updatedByLTE", "updatedByContains", "updatedByHasPrefix", "updatedByHasSuffix", "updatedByIsNil", "updatedByNotNil", "updatedByEqualFold", "updatedByContainsFold", "number", "numberNEQ", "numberIn", "numberNotIn", "numberGT", "numberGTE", "numberLT", "numberLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "hasPools", "hasPoolsWith", "hasLoadBalancer", "hasLoadBalancerWith"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "updatedAt", "updatedAtNEQ", "updatedAtIn", "updatedAtNotIn", "updatedAtGT", "updatedAtGTE", "updatedAtLT", "updatedAtLTE", "deletedAt", "deletedAtNEQ", "deletedAtIn", "deletedAtNotIn", "deletedAtGT", "deletedAtGTE", "deletedAtLT", "deletedAtLTE", "deletedAtIsNil", "deletedAtNotNil", "deletedBy", "deletedByNEQ", "deletedByIn", "deletedByNotIn", "deletedByGT", "deletedByGTE", "deletedByLT", "deletedByLTE", "deletedByContains", "deletedByHasPrefix", "deletedByHasSuffix", "deletedByIsNil", "deletedByNotNil", "deletedByEqualFold", "deletedByContainsFold", "createdBy", "createdByNEQ", "createdByIn", "createdByNotIn", "createdByGT", "createdByGTE", "createdByLT", "createdByLTE", "createdByContains", "createdByHasPrefix", "createdByHasSuffix", "createdByIsNil", "createdByNotNil", "createdByEqualFold", "createdByContainsFold", "updatedBy", "updatedByNEQ", "updatedByIn", "updatedByNotIn", "updatedByGT", "updatedByGTE", "updatedByLT", "updatedByLTE", "updatedByContains", "updatedByHasPrefix", "updatedByHasSuffix", "updatedByIsNil", "updatedByNotNil", "updatedByEqualFold", "updatedByContainsFold", "number", "numberNEQ", "numberIn", "numberNotIn", "numberGT", "numberGTE", "numberLT", "numberLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameIsNil", "nameNotNil", "nameEqualFold", "nameContainsFold", "hasPools", "hasPoolsWith", "hasLoadBalancer", "hasLoadBalancerWith"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -17188,6 +17188,24 @@ func (ec *executionContext) unmarshalInputLoadBalancerPortWhereInput(ctx context return it, err } it.NameHasSuffix = data + case "nameIsNil": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameIsNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameIsNil = data + case "nameNotNil": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameNotNil")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.NameNotNil = data case "nameEqualFold": var err error @@ -19314,7 +19332,7 @@ func (ec *executionContext) unmarshalInputUpdateLoadBalancerPortInput(ctx contex asMap[k] = v } - fieldsInOrder := [...]string{"number", "name", "addPoolIDs", "removePoolIDs", "clearPools"} + fieldsInOrder := [...]string{"number", "name", "clearName", "addPoolIDs", "removePoolIDs", "clearPools"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -19339,6 +19357,15 @@ func (ec *executionContext) unmarshalInputUpdateLoadBalancerPortInput(ctx contex return it, err } it.Name = data + case "clearName": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearName")) + data, err := ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.ClearName = data case "addPoolIDs": var err error @@ -20846,9 +20873,6 @@ func (ec *executionContext) _LoadBalancerPort(ctx context.Context, sel ast.Selec } case "name": out.Values[i] = ec._LoadBalancerPort_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) - } case "loadBalancerID": out.Values[i] = ec._LoadBalancerPort_loadBalancerID(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/internal/graphapi/loadbalancer_test.go b/internal/graphapi/loadbalancer_test.go index bc1fa420c..f99daf3ee 100644 --- a/internal/graphapi/loadbalancer_test.go +++ b/internal/graphapi/loadbalancer_test.go @@ -397,7 +397,7 @@ func TestFullLoadBalancerLifecycle(t *testing.T) { assert.Equal(t, ownerID, createdLB.Owner.ID) createdPortResp, err := graphTestClient().LoadBalancerPortCreate(ctx, graphclient.CreateLoadBalancerPortInput{ - Name: gofakeit.DomainName(), + Name: newString(gofakeit.DomainName()), Number: 8080, LoadBalancerID: createdLB.ID, }) diff --git a/internal/graphapi/port_test.go b/internal/graphapi/port_test.go index ac8e12ee8..f34a0e986 100644 --- a/internal/graphapi/port_test.go +++ b/internal/graphapi/port_test.go @@ -43,31 +43,43 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "creates loadbalancer port", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 22, }, Expected: &graphclient.LoadBalancerPort{ - Name: "lb-port", + Name: newString("lb-port"), Number: 22, }, }, { TestName: "succeeds in creating loadbalancer port with empty name", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "", + Name: newString(""), LoadBalancerID: lb.ID, Number: 23, }, Expected: &graphclient.LoadBalancerPort{ - Name: "", + Name: newString(""), Number: 23, }, }, + { + TestName: "succeeds in creating loadbalancer port with nil name", + Input: graphclient.CreateLoadBalancerPortInput{ + Name: nil, + LoadBalancerID: lb.ID, + Number: 24, + }, + Expected: &graphclient.LoadBalancerPort{ + Name: newString(""), + Number: 24, + }, + }, { TestName: "fails to create loadbalancer port with empty loadbalancer id", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: "", Number: 22, }, @@ -76,7 +88,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with number < min", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 0, }, @@ -85,7 +97,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with number > max", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 65536, }, @@ -94,7 +106,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with duplicate port number", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 80, }, @@ -103,7 +115,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with restricted port number", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 1234, }, @@ -112,7 +124,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with invalid pool id", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 1234, PoolIDs: []gidx.PrefixedID{"not-a-valid-pool-id"}, @@ -122,7 +134,7 @@ func TestCreate_LoadbalancerPort(t *testing.T) { { TestName: "fails to create loadbalancer port with pool with conflicting OwnerID", Input: graphclient.CreateLoadBalancerPortInput{ - Name: "lb-port", + Name: newString("lb-port"), LoadBalancerID: lb.ID, Number: 1234, PoolIDs: []gidx.PrefixedID{poolBad.ID}, @@ -208,7 +220,7 @@ func TestUpdate_LoadbalancerPort(t *testing.T) { Name: newString("lb-port"), }, Expected: &graphclient.LoadBalancerPort{ - Name: "lb-port", + Name: newString("lb-port"), Number: 80, }, }, @@ -219,7 +231,7 @@ func TestUpdate_LoadbalancerPort(t *testing.T) { Number: newInt64(22), }, Expected: &graphclient.LoadBalancerPort{ - Name: "lb-port", + Name: newString("lb-port"), Number: 22, }, }, @@ -230,7 +242,7 @@ func TestUpdate_LoadbalancerPort(t *testing.T) { Name: newString(""), }, Expected: &graphclient.LoadBalancerPort{ - Name: "", + Name: newString(""), Number: 22, }, }, @@ -376,7 +388,7 @@ func TestFullLoadBalancerPortLifecycle(t *testing.T) { ctx = context.WithValue(ctx, permissions.CheckerCtxKey, permissions.DefaultAllowChecker) lb := (&testutils.LoadBalancerBuilder{}).MustNew(ctx) - name := gofakeit.DomainName() + name := newString(gofakeit.DomainName()) createdPortResp, err := graphTestClient().LoadBalancerPortCreate(ctx, graphclient.CreateLoadBalancerPortInput{ Name: name, diff --git a/internal/graphclient/gen_client.go b/internal/graphclient/gen_client.go index 9ea78f952..531b6a7f5 100644 --- a/internal/graphclient/gen_client.go +++ b/internal/graphclient/gen_client.go @@ -247,7 +247,7 @@ type LoadBalancerPortCreate struct { LoadBalancerPortCreate struct { LoadBalancerPort struct { ID gidx.PrefixedID "json:\"id\" graphql:\"id\"" - Name string "json:\"name\" graphql:\"name\"" + Name *string "json:\"name\" graphql:\"name\"" Number int64 "json:\"number\" graphql:\"number\"" LoadBalancer struct { ID gidx.PrefixedID "json:\"id\" graphql:\"id\"" @@ -266,7 +266,7 @@ type LoadBalancerPortUpdate struct { LoadBalancerPortUpdate struct { LoadBalancerPort struct { ID gidx.PrefixedID "json:\"id\" graphql:\"id\"" - Name string "json:\"name\" graphql:\"name\"" + Name *string "json:\"name\" graphql:\"name\"" Number int64 "json:\"number\" graphql:\"number\"" CreatedAt time.Time "json:\"createdAt\" graphql:\"createdAt\"" UpdatedAt time.Time "json:\"updatedAt\" graphql:\"updatedAt\"" diff --git a/internal/graphclient/gen_models.go b/internal/graphclient/gen_models.go index 83649876b..2cb0ba509 100644 --- a/internal/graphclient/gen_models.go +++ b/internal/graphclient/gen_models.go @@ -70,7 +70,7 @@ type CreateLoadBalancerPoolInput struct { // Input was generated by ent. type CreateLoadBalancerPortInput struct { Number int64 `json:"number"` - Name string `json:"name"` + Name *string `json:"name,omitempty"` PoolIDs []gidx.PrefixedID `json:"poolIDs,omitempty"` LoadBalancerID gidx.PrefixedID `json:"loadBalancerID"` } @@ -562,7 +562,7 @@ type LoadBalancerPort struct { CreatedBy *string `json:"createdBy,omitempty"` UpdatedBy *string `json:"updatedBy,omitempty"` Number int64 `json:"number"` - Name string `json:"name"` + Name *string `json:"name,omitempty"` LoadBalancerID gidx.PrefixedID `json:"loadBalancerID"` Pools []*LoadBalancerPool `json:"pools,omitempty"` LoadBalancer LoadBalancer `json:"loadBalancer"` @@ -732,6 +732,8 @@ type LoadBalancerPortWhereInput struct { NameContains *string `json:"nameContains,omitempty"` NameHasPrefix *string `json:"nameHasPrefix,omitempty"` NameHasSuffix *string `json:"nameHasSuffix,omitempty"` + NameIsNil *bool `json:"nameIsNil,omitempty"` + NameNotNil *bool `json:"nameNotNil,omitempty"` NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` // pools edge predicates @@ -1106,6 +1108,7 @@ type UpdateLoadBalancerPoolInput struct { type UpdateLoadBalancerPortInput struct { Number *int64 `json:"number,omitempty"` Name *string `json:"name,omitempty"` + ClearName *bool `json:"clearName,omitempty"` AddPoolIDs []gidx.PrefixedID `json:"addPoolIDs,omitempty"` RemovePoolIDs []gidx.PrefixedID `json:"removePoolIDs,omitempty"` ClearPools *bool `json:"clearPools,omitempty"` diff --git a/internal/graphclient/schema/schema.graphql b/internal/graphclient/schema/schema.graphql index 3454585ec..b67487a59 100644 --- a/internal/graphclient/schema/schema.graphql +++ b/internal/graphclient/schema/schema.graphql @@ -51,7 +51,7 @@ Input was generated by ent. """ input CreateLoadBalancerPortInput { number: Int! - name: String! + name: String poolIDs: [ID!] loadBalancerID: ID! } @@ -587,7 +587,7 @@ type LoadBalancerPort implements Node @key(fields: "id") @prefixedID(prefix: "lo createdBy: String updatedBy: String number: Int! - name: String! + name: String loadBalancerID: ID! pools: [LoadBalancerPool!] loadBalancer: LoadBalancer! @@ -756,6 +756,8 @@ input LoadBalancerPortWhereInput { nameContains: String nameHasPrefix: String nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean nameEqualFold: String nameContainsFold: String """pools edge predicates""" @@ -1311,6 +1313,7 @@ Input was generated by ent. input UpdateLoadBalancerPortInput { number: Int name: String + clearName: Boolean addPoolIDs: [ID!] removePoolIDs: [ID!] clearPools: Boolean diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 85e568cf2..572e1485f 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -277,11 +277,11 @@ func TestNodeMetadata(t *testing.T) { func mustNewGQLTestClient(respJSON string, respCode int) *graphql.Client { mux := http.NewServeMux() - mux.HandleFunc("/query", func(w http.ResponseWriter, req *http.Request) { + mux.HandleFunc("/query", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(respCode) w.Header().Set("Content-Type", "application/json") - _, err := io.WriteString(w, respJSON) + _, err := io.WriteString(w, respJSON) if err != nil { panic(err) } diff --git a/schema.graphql b/schema.graphql index 5d0a66846..9338b92b9 100644 --- a/schema.graphql +++ b/schema.graphql @@ -39,7 +39,7 @@ Input was generated by ent. """ input CreateLoadBalancerPortInput { number: Int! - name: String! + name: String poolIDs: [ID!] loadBalancerID: ID! } @@ -574,7 +574,7 @@ type LoadBalancerPort implements Node @key(fields: "id") @prefixedID(prefix: "lo createdBy: String updatedBy: String number: Int! - name: String! + name: String loadBalancerID: ID! pools: [LoadBalancerPool!] loadBalancer: LoadBalancer! @@ -743,6 +743,8 @@ input LoadBalancerPortWhereInput { nameContains: String nameHasPrefix: String nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean nameEqualFold: String nameContainsFold: String """pools edge predicates""" @@ -1298,6 +1300,7 @@ Input was generated by ent. input UpdateLoadBalancerPortInput { number: Int name: String + clearName: Boolean addPoolIDs: [ID!] removePoolIDs: [ID!] clearPools: Boolean diff --git a/schema/ent.graphql b/schema/ent.graphql index 05bb01b5d..677f4dab5 100644 --- a/schema/ent.graphql +++ b/schema/ent.graphql @@ -40,7 +40,7 @@ Input was generated by ent. """ input CreateLoadBalancerPortInput { number: Int! - name: String! + name: String poolIDs: [ID!] loadBalancerID: ID! } @@ -526,7 +526,7 @@ type LoadBalancerPort implements Node @key(fields: "id") @prefixedID(prefix: "lo createdBy: String updatedBy: String number: Int! - name: String! + name: String loadBalancerID: ID! pools: [LoadBalancerPool!] loadBalancer: LoadBalancer! @@ -680,6 +680,8 @@ input LoadBalancerPortWhereInput { nameContains: String nameHasPrefix: String nameHasSuffix: String + nameIsNil: Boolean + nameNotNil: Boolean nameEqualFold: String nameContainsFold: String """pools edge predicates""" @@ -1074,6 +1076,7 @@ Input was generated by ent. input UpdateLoadBalancerPortInput { number: Int name: String + clearName: Boolean addPoolIDs: [ID!] removePoolIDs: [ID!] clearPools: Boolean diff --git a/x/pubsubinfo/gql_hooks.go b/x/pubsubinfo/gql_hooks.go index 7a0a6db49..c310c2e01 100644 --- a/x/pubsubinfo/gql_hooks.go +++ b/x/pubsubinfo/gql_hooks.go @@ -26,7 +26,7 @@ import ( // //nolint:goerr113 var ( - removeNodeGoModel = func(g *gen.Graph, s *ast.Schema) error { + removeNodeGoModel = func(_ *gen.Graph, s *ast.Schema) error { n, ok := s.Types["Node"] if !ok { return errors.New("failed to find node interface in schema") @@ -47,7 +47,7 @@ var ( return nil } - removeNodeQueries = func(g *gen.Graph, s *ast.Schema) error { + removeNodeQueries = func(_ *gen.Graph, s *ast.Schema) error { q, ok := s.Types["Query"] if !ok { return errors.New("failed to find query definition in schema") @@ -69,7 +69,7 @@ var ( return nil } - setPageInfoShareable = func(g *gen.Graph, s *ast.Schema) error { + setPageInfoShareable = func(_ *gen.Graph, s *ast.Schema) error { q, ok := s.Types["PageInfo"] if !ok { return nil @@ -80,7 +80,7 @@ var ( return nil } - addJSONScalar = func(g *gen.Graph, s *ast.Schema) error { + addJSONScalar = func(_ *gen.Graph, s *ast.Schema) error { s.Types["JSON"] = &ast.Definition{ Kind: ast.Scalar, Description: "A valid JSON string.",