Skip to content

Enhance KV existence checks for better reliability and bugfix on creating MCI.#2125

Merged
cb-github-robot merged 2 commits intocloud-barista:mainfrom
yunkon-kim:250828-22
Aug 28, 2025
Merged

Enhance KV existence checks for better reliability and bugfix on creating MCI.#2125
cb-github-robot merged 2 commits intocloud-barista:mainfrom
yunkon-kim:250828-22

Conversation

@yunkon-kim
Copy link
Copy Markdown
Member

This pull request introduces a more robust method for checking key existence in our kvstore operations by using an explicit exists flag.

Key Changes

  • Explicit Existence Checks: Replaced ambiguous empty struct comparisons with clear boolean flag checks
    • Note - structs containing map cannot be directly compared like this pattern if keyValue != (kvstore.KeyValue{})
  • Better Error Handling: Distinguished between actual errors and "key not found" scenarios
  • Incremental Migration: Used _ placeholder where full refactoring wasn't immediately feasible, marking areas for future improvement

Example Change

-	keyValue, err := kvstore.GetKv(key)
-	if keyValue != (kvstore.KeyValue{}) {
+	_, exists, err := kvstore.GetKv(key)
+	if exists {
        return true, nil
    }

Benefits

  • Eliminates unreliable struct comparisons (especially for structs containing maps/slices)
  • Provides clearer intent in code
  • Improves debugging and error handling
  • Sets foundation for complete kvstore operation standardization

Test

  • 1 test case performed on MapUI: Create MCI on AWS.

- Use exists flag instead of comparing empty KeyValue struct
- Add proper checks for key existence in kvstore operations
- Improve error handling when keys are not found
- Fix inconsistent key validation across all modules
@yunkon-kim yunkon-kim requested a review from seokho-son as a code owner August 28, 2025 16:28
@yunkon-kim yunkon-kim requested a review from Copilot August 28, 2025 16:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances key-value store operations by replacing unreliable struct comparisons with explicit existence checks using a boolean flag. The primary motivation is to fix issues where structs containing maps cannot be directly compared using the pattern if keyValue != (kvstore.KeyValue{}), which could lead to runtime panics.

  • Modifies kvstore interface methods to return an additional exists boolean parameter
  • Updates all calling code to use the explicit existence flag instead of empty struct comparisons
  • Uses _ placeholder for cases where the existence check isn't immediately needed

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/kvstore/kvstore/kvstore.go Updates kvstore interface to return existence boolean for Get methods
src/kvstore/etcd/etcd.go Implements the new interface with proper existence checks for etcd backend
src/core/resource/*.go Updates resource management code to use new existence checks
src/core/infra/*.go Updates infrastructure code to use new existence checks
src/core/common/*.go Updates common utilities to use new existence checks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@seokho-son
Copy link
Copy Markdown
Member

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Aug 28, 2025
@cb-github-robot cb-github-robot merged commit d127fc5 into cloud-barista:main Aug 28, 2025
5 checks passed
@yunkon-kim yunkon-kim deleted the 250828-22 branch September 22, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants