From ccc4edb84931315a98b7c311e8e856c062dc8918 Mon Sep 17 00:00:00 2001 From: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> Date: Fri, 8 May 2026 18:13:13 -0400 Subject: [PATCH 1/2] OSAC-779: use DELETING state in PublicIP feedback controller The feedback controller's handleDelete() was setting RELEASING when a PublicIP CR was being deleted. RELEASING is for the detach flow (ATTACHED -> RELEASING -> ALLOCATED), not for resource deletion. The fulfillment-service state machine rejected ALLOCATED -> RELEASING, leaving the CR stuck in Deleting phase. Now handleDelete() sets DELETING, matching the pattern used by the Subnet feedback controller. The detach flow through syncState() continues to use RELEASING unchanged. Bumps private-api BSR module from v0.0.60 to v0.0.61 which adds the PUBLIC_IP_STATE_DELETING enum value. Signed-off-by: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> Assisted-by: Cursor/Claude Signed-off-by: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> --- buf.gen.yaml | 2 +- .../api/osac/private/v1/public_ip_type.pb.go | 46 +++++++++++-------- .../v1/public_ip_type_protoopaque.pb.go | 46 +++++++++++-------- .../publicip_feedback_controller.go | 2 +- .../publicip_feedback_controller_test.go | 4 +- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index 1b629cd6..03e5129c 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -24,7 +24,7 @@ managed: inputs: -- module: buf.build/osac-project/private-api:v0.0.60 +- module: buf.build/osac-project/private-api:v0.0.61 plugins: diff --git a/internal/api/osac/private/v1/public_ip_type.pb.go b/internal/api/osac/private/v1/public_ip_type.pb.go index 4a1c64b1..132f93b1 100644 --- a/internal/api/osac/private/v1/public_ip_type.pb.go +++ b/internal/api/osac/private/v1/public_ip_type.pb.go @@ -70,18 +70,22 @@ const ( // Clearing the compute_instance field detaches the IP, transitioning through RELEASING // back to ALLOCATED. PublicIPState_PUBLIC_IP_STATE_ATTACHED PublicIPState = 4 - // The public IP is being released from its current binding. + // The public IP is being released from its current ComputeInstance binding. // // On detach (clearing spec.compute_instance from an ATTACHED IP), the system unbinds // the address from the ComputeInstance. The address is preserved and the IP returns to - // ALLOCATED once complete. On deallocation (deleting the PublicIP), the system removes - // the MetalLB LoadBalancer Service and returns the address to the pool. + // ALLOCATED once complete. PublicIPState_PUBLIC_IP_STATE_RELEASING PublicIPState = 5 // Provisioning or release failed. Check status.message for error details. // // This is a terminal error state. The PublicIP may require manual intervention // (e.g., deleting and recreating) or a Signal RPC to retry the operation. PublicIPState_PUBLIC_IP_STATE_FAILED PublicIPState = 6 + // The public IP is being deprovisioned and will be removed. + // + // On deletion of an ALLOCATED PublicIP, the system removes the MetalLB LoadBalancer + // Service and returns the address to the pool. Only ALLOCATED PublicIPs can be deleted. + PublicIPState_PUBLIC_IP_STATE_DELETING PublicIPState = 7 ) // Enum value maps for PublicIPState. @@ -94,6 +98,7 @@ var ( 4: "PUBLIC_IP_STATE_ATTACHED", 5: "PUBLIC_IP_STATE_RELEASING", 6: "PUBLIC_IP_STATE_FAILED", + 7: "PUBLIC_IP_STATE_DELETING", } PublicIPState_value = map[string]int32{ "PUBLIC_IP_STATE_UNSPECIFIED": 0, @@ -103,6 +108,7 @@ var ( "PUBLIC_IP_STATE_ATTACHED": 4, "PUBLIC_IP_STATE_RELEASING": 5, "PUBLIC_IP_STATE_FAILED": 6, + "PUBLIC_IP_STATE_DELETING": 7, } ) @@ -596,7 +602,7 @@ var file_osac_private_v1_public_ip_type_proto_rawDesc = string([]byte{ 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x17, 0x0a, 0x04, 0x70, 0x6f, 0x6f, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x04, 0x70, 0x6f, 0x6f, 0x6c, 0x42, - 0x0a, 0x0a, 0x08, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0xe4, 0x01, 0x0a, 0x0d, + 0x0a, 0x0a, 0x08, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x82, 0x02, 0x0a, 0x0d, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x50, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x1b, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1b, @@ -611,21 +617,23 @@ var file_osac_private_v1_public_ip_type_proto_rawDesc = string([]byte{ 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x49, 0x4e, 0x47, 0x10, 0x05, 0x12, 0x1a, 0x0a, 0x16, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, - 0x10, 0x06, 0x42, 0xd6, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x73, 0x61, 0x63, 0x2e, - 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x11, 0x50, 0x75, 0x62, 0x6c, - 0x69, 0x63, 0x49, 0x70, 0x54, 0x79, 0x70, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x4c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x73, 0x61, 0x63, - 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x6f, 0x70, - 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, - 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, - 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x0f, 0x4f, 0x73, 0x61, 0x63, 0x2e, 0x50, 0x72, 0x69, 0x76, 0x61, - 0x74, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, 0x69, - 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x4f, 0x73, 0x61, 0x63, 0x5c, - 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x4f, 0x73, 0x61, 0x63, 0x3a, 0x3a, - 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x10, 0x06, 0x12, 0x1c, 0x0a, 0x18, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, + 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x49, 0x4e, 0x47, 0x10, 0x07, + 0x42, 0xd6, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x73, 0x61, 0x63, 0x2e, 0x70, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x11, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, + 0x49, 0x70, 0x54, 0x79, 0x70, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x4c, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x70, + 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x6f, 0x70, 0x65, 0x72, + 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, + 0x31, 0x3b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, + 0x58, 0xaa, 0x02, 0x0f, 0x4f, 0x73, 0x61, 0x63, 0x2e, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, 0x69, 0x76, 0x61, + 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x4f, 0x73, 0x61, 0x63, 0x3a, 0x3a, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, }) var file_osac_private_v1_public_ip_type_proto_enumTypes = make([]protoimpl.EnumInfo, 1) diff --git a/internal/api/osac/private/v1/public_ip_type_protoopaque.pb.go b/internal/api/osac/private/v1/public_ip_type_protoopaque.pb.go index 7d943d88..dadd89ef 100644 --- a/internal/api/osac/private/v1/public_ip_type_protoopaque.pb.go +++ b/internal/api/osac/private/v1/public_ip_type_protoopaque.pb.go @@ -70,18 +70,22 @@ const ( // Clearing the compute_instance field detaches the IP, transitioning through RELEASING // back to ALLOCATED. PublicIPState_PUBLIC_IP_STATE_ATTACHED PublicIPState = 4 - // The public IP is being released from its current binding. + // The public IP is being released from its current ComputeInstance binding. // // On detach (clearing spec.compute_instance from an ATTACHED IP), the system unbinds // the address from the ComputeInstance. The address is preserved and the IP returns to - // ALLOCATED once complete. On deallocation (deleting the PublicIP), the system removes - // the MetalLB LoadBalancer Service and returns the address to the pool. + // ALLOCATED once complete. PublicIPState_PUBLIC_IP_STATE_RELEASING PublicIPState = 5 // Provisioning or release failed. Check status.message for error details. // // This is a terminal error state. The PublicIP may require manual intervention // (e.g., deleting and recreating) or a Signal RPC to retry the operation. PublicIPState_PUBLIC_IP_STATE_FAILED PublicIPState = 6 + // The public IP is being deprovisioned and will be removed. + // + // On deletion of an ALLOCATED PublicIP, the system removes the MetalLB LoadBalancer + // Service and returns the address to the pool. Only ALLOCATED PublicIPs can be deleted. + PublicIPState_PUBLIC_IP_STATE_DELETING PublicIPState = 7 ) // Enum value maps for PublicIPState. @@ -94,6 +98,7 @@ var ( 4: "PUBLIC_IP_STATE_ATTACHED", 5: "PUBLIC_IP_STATE_RELEASING", 6: "PUBLIC_IP_STATE_FAILED", + 7: "PUBLIC_IP_STATE_DELETING", } PublicIPState_value = map[string]int32{ "PUBLIC_IP_STATE_UNSPECIFIED": 0, @@ -103,6 +108,7 @@ var ( "PUBLIC_IP_STATE_ATTACHED": 4, "PUBLIC_IP_STATE_RELEASING": 5, "PUBLIC_IP_STATE_FAILED": 6, + "PUBLIC_IP_STATE_DELETING": 7, } ) @@ -582,7 +588,7 @@ var file_osac_private_v1_public_ip_type_proto_rawDesc = string([]byte{ 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x17, 0x0a, 0x04, 0x70, 0x6f, 0x6f, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x04, 0x70, 0x6f, 0x6f, 0x6c, 0x42, - 0x0a, 0x0a, 0x08, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0xe4, 0x01, 0x0a, 0x0d, + 0x0a, 0x0a, 0x08, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x82, 0x02, 0x0a, 0x0d, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x50, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x1b, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1b, @@ -597,21 +603,23 @@ var file_osac_private_v1_public_ip_type_proto_rawDesc = string([]byte{ 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x49, 0x4e, 0x47, 0x10, 0x05, 0x12, 0x1a, 0x0a, 0x16, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, - 0x10, 0x06, 0x42, 0xd6, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x73, 0x61, 0x63, 0x2e, - 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x11, 0x50, 0x75, 0x62, 0x6c, - 0x69, 0x63, 0x49, 0x70, 0x54, 0x79, 0x70, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x4c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x73, 0x61, 0x63, - 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x6f, 0x70, - 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, - 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, - 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x0f, 0x4f, 0x73, 0x61, 0x63, 0x2e, 0x50, 0x72, 0x69, 0x76, 0x61, - 0x74, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, 0x69, - 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x4f, 0x73, 0x61, 0x63, 0x5c, - 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x4f, 0x73, 0x61, 0x63, 0x3a, 0x3a, - 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x10, 0x06, 0x12, 0x1c, 0x0a, 0x18, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x5f, 0x49, 0x50, 0x5f, + 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x49, 0x4e, 0x47, 0x10, 0x07, + 0x42, 0xd6, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x73, 0x61, 0x63, 0x2e, 0x70, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x11, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, + 0x49, 0x70, 0x54, 0x79, 0x70, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x4c, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x70, + 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2d, 0x6f, 0x70, 0x65, 0x72, + 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x6f, 0x73, 0x61, 0x63, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, + 0x31, 0x3b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, + 0x58, 0xaa, 0x02, 0x0f, 0x4f, 0x73, 0x61, 0x63, 0x2e, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, 0x69, 0x76, 0x61, + 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x4f, 0x73, 0x61, 0x63, 0x5c, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x4f, 0x73, 0x61, 0x63, 0x3a, 0x3a, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, }) var file_osac_private_v1_public_ip_type_proto_enumTypes = make([]protoimpl.EnumInfo, 1) diff --git a/internal/controller/publicip_feedback_controller.go b/internal/controller/publicip_feedback_controller.go index 2f8f0d85..b6bd3aff 100644 --- a/internal/controller/publicip_feedback_controller.go +++ b/internal/controller/publicip_feedback_controller.go @@ -221,7 +221,7 @@ func (t *publicIPFeedbackReconcilerTask) handleDelete() { t.publicIP.GetStatus().SetState(privatev1.PublicIPState_PUBLIC_IP_STATE_FAILED) return } - t.publicIP.GetStatus().SetState(privatev1.PublicIPState_PUBLIC_IP_STATE_RELEASING) + t.publicIP.GetStatus().SetState(privatev1.PublicIPState_PUBLIC_IP_STATE_DELETING) } func (t *publicIPFeedbackReconcilerTask) syncState(ctx context.Context) { diff --git a/internal/controller/publicip_feedback_controller_test.go b/internal/controller/publicip_feedback_controller_test.go index 352e80cb..1c2c3b4d 100644 --- a/internal/controller/publicip_feedback_controller_test.go +++ b/internal/controller/publicip_feedback_controller_test.go @@ -511,7 +511,7 @@ var _ = Describe("PublicIPFeedbackController", func() { Expect(err).NotTo(HaveOccurred()) Expect(mockServer.updates).To(HaveLen(1)) - Expect(mockServer.updates[0].GetStatus().GetState()).To(Equal(privatev1.PublicIPState_PUBLIC_IP_STATE_RELEASING)) + Expect(mockServer.updates[0].GetStatus().GetState()).To(Equal(privatev1.PublicIPState_PUBLIC_IP_STATE_DELETING)) updated := &v1alpha1.PublicIP{} Expect(k8sClient.Get(ctx, types.NamespacedName{Name: publicIPName, Namespace: publicIPNamespace}, updated)).To(Succeed()) @@ -610,7 +610,7 @@ var _ = Describe("PublicIPFeedbackController", func() { Expect(err).NotTo(HaveOccurred()) Expect(mockServer.updates).To(HaveLen(1)) - Expect(mockServer.updates[0].GetStatus().GetState()).To(Equal(privatev1.PublicIPState_PUBLIC_IP_STATE_RELEASING)) + Expect(mockServer.updates[0].GetStatus().GetState()).To(Equal(privatev1.PublicIPState_PUBLIC_IP_STATE_DELETING)) Expect(mockServer.signals).To(HaveLen(1)) Expect(mockServer.signals[0]).To(Equal(publicIPID)) From 2cb9ac6d116b7843300493c4d11f2177fd53821d Mon Sep 17 00:00:00 2001 From: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> Date: Fri, 8 May 2026 23:02:45 -0400 Subject: [PATCH 2/2] OSAC-780: fix target-namespace annotation deleted before detach The annotation sync in syncComputeInstanceTargetNamespaceAnnotation() runs before the state transition from ATTACHED to RELEASING in handleUpdate(). The OSAC-776 preservation check tested for state == RELEASING, but the state was still ATTACHED at that point, so the annotation was always deleted before the AAP detach job could use it. Changed the condition from "preserve only during RELEASING" to "only clean up when ALLOCATED" (detach fully completed). This ensures the annotation survives the entire detach flow regardless of reconciliation ordering. Signed-off-by: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> Assisted-by: Cursor/Claude Signed-off-by: akshaynadkarni <25892229+akshaynadkarni@users.noreply.github.com> --- internal/controller/publicip_controller.go | 2 +- .../controller/publicip_controller_test.go | 73 ++++++++++++++----- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/internal/controller/publicip_controller.go b/internal/controller/publicip_controller.go index 2bb9f6e4..1ff4aa7e 100644 --- a/internal/controller/publicip_controller.go +++ b/internal/controller/publicip_controller.go @@ -329,7 +329,7 @@ func (r *PublicIPReconciler) syncComputeInstanceTargetNamespaceAnnotation( if publicIP.Spec.ComputeInstance == "" { if _, ok := publicIP.Annotations[osacPublicIPTargetNamespaceAnnotation]; ok { - if publicIP.Status.State != v1alpha1.PublicIPStateReleasing { + if publicIP.Status.State == v1alpha1.PublicIPStateAllocated { delete(publicIP.Annotations, osacPublicIPTargetNamespaceAnnotation) log.Info("cleared publicip-target-namespace annotation") return true, false, nil diff --git a/internal/controller/publicip_controller_test.go b/internal/controller/publicip_controller_test.go index 0c796f80..4f48aea6 100644 --- a/internal/controller/publicip_controller_test.go +++ b/internal/controller/publicip_controller_test.go @@ -1313,8 +1313,8 @@ var _ = Describe("PublicIPReconciler", func() { Expect(updated.Annotations[osacPublicIPTargetNamespaceAnnotation]).To(Equal(testTenantNS)) }) - It("should clear publicip-target-namespace annotation when computeInstance is cleared", func() { - ipWithAnnotation := &osacv1alpha1.PublicIP{ + It("should clear publicip-target-namespace annotation when computeInstance is cleared and state is Allocated", func() { + pip := &osacv1alpha1.PublicIP{ ObjectMeta: metav1.ObjectMeta{ Name: "ip-clear-ci", Namespace: testNamespace, @@ -1326,32 +1326,69 @@ var _ = Describe("PublicIPReconciler", func() { Spec: osacv1alpha1.PublicIPSpec{ Pool: testPoolUUID, }, + Status: osacv1alpha1.PublicIPStatus{ + State: osacv1alpha1.PublicIPStateAllocated, + }, + } + + rec := &PublicIPReconciler{ + Client: fake.NewClientBuilder().WithScheme(testScheme).Build(), + APIReader: fake.NewClientBuilder().WithScheme(testScheme).Build(), + Scheme: testScheme, + ComputeInstanceNamespace: testCINamespace, + } + + changed, _, err := rec.syncComputeInstanceTargetNamespaceAnnotation(testCtx, pip) + Expect(err).NotTo(HaveOccurred()) + Expect(changed).To(BeTrue(), "should report annotation changed") + _, exists := pip.Annotations[osacPublicIPTargetNamespaceAnnotation] + Expect(exists).To(BeFalse(), "annotation should be cleared when state is Allocated") + }) + + It("should preserve publicip-target-namespace annotation during detach (Releasing state)", func() { + pip := &osacv1alpha1.PublicIP{ + ObjectMeta: metav1.ObjectMeta{ + Name: "ip-releasing", + Namespace: testNamespace, + Annotations: map[string]string{ + osacPublicIPTargetNamespaceAnnotation: testTenantNS, + }, + Finalizers: []string{osacPublicIPFinalizer}, + }, + Spec: osacv1alpha1.PublicIPSpec{ + Pool: testPoolUUID, + }, } - clearClient := fake.NewClientBuilder(). + fc := fake.NewClientBuilder(). WithScheme(testScheme). - WithObjects(ipWithAnnotation, parentPool). + WithObjects(pip, parentPool). WithStatusSubresource(&osacv1alpha1.PublicIP{}). Build() - reconciler.Client = clearClient - reconciler.APIReader = clearClient + pip.Status.State = osacv1alpha1.PublicIPStateReleasing + Expect(fc.Status().Update(testCtx, pip)).To(Succeed()) - key := types.NamespacedName{Name: ipWithAnnotation.Name, Namespace: ipWithAnnotation.Namespace} + rec := &PublicIPReconciler{ + Client: fc, + APIReader: fc, + Scheme: testScheme, + ComputeInstanceNamespace: testCINamespace, + } - _, err := reconciler.Reconcile(testCtx, mcreconcile.Request{Request: ctrl.Request{NamespacedName: key}}) - Expect(err).NotTo(HaveOccurred()) + Expect(fc.Get(testCtx, client.ObjectKeyFromObject(pip), pip)).To(Succeed()) - updated := &osacv1alpha1.PublicIP{} - Expect(clearClient.Get(testCtx, key, updated)).To(Succeed()) - _, exists := updated.Annotations[osacPublicIPTargetNamespaceAnnotation] - Expect(exists).To(BeFalse()) + changed, _, err := rec.syncComputeInstanceTargetNamespaceAnnotation(testCtx, pip) + Expect(err).NotTo(HaveOccurred()) + Expect(changed).To(BeFalse(), "should not change annotation during detach") + _, exists := pip.Annotations[osacPublicIPTargetNamespaceAnnotation] + Expect(exists).To(BeTrue(), "annotation should be preserved during Releasing state") }) - It("should preserve publicip-target-namespace annotation during detach", func() { + It("should preserve publicip-target-namespace annotation when Attached and computeInstance cleared", func() { pip := &osacv1alpha1.PublicIP{ ObjectMeta: metav1.ObjectMeta{ - Name: "ip-releasing", + Name: "ip-attached-detaching", Namespace: testNamespace, Annotations: map[string]string{ osacPublicIPTargetNamespaceAnnotation: testTenantNS, @@ -1369,7 +1406,7 @@ var _ = Describe("PublicIPReconciler", func() { WithStatusSubresource(&osacv1alpha1.PublicIP{}). Build() - pip.Status.State = osacv1alpha1.PublicIPStateReleasing + pip.Status.State = osacv1alpha1.PublicIPStateAttached Expect(fc.Status().Update(testCtx, pip)).To(Succeed()) rec := &PublicIPReconciler{ @@ -1383,9 +1420,9 @@ var _ = Describe("PublicIPReconciler", func() { changed, _, err := rec.syncComputeInstanceTargetNamespaceAnnotation(testCtx, pip) Expect(err).NotTo(HaveOccurred()) - Expect(changed).To(BeFalse(), "should not change annotation during detach") + Expect(changed).To(BeFalse(), "should not change annotation when Attached and about to detach") _, exists := pip.Annotations[osacPublicIPTargetNamespaceAnnotation] - Expect(exists).To(BeTrue(), "annotation should be preserved during Releasing state") + Expect(exists).To(BeTrue(), "annotation should be preserved during Attached state before detach") }) It("should requeue when ComputeInstance not found", func() {