Skip to content

Feature implementation from commits 984acef..6ccc2c0 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: feature-base-branch-2
Choose a base branch
from

Conversation

codeOwlAI
Copy link
Owner

@codeOwlAI codeOwlAI commented Jun 29, 2025

PR Summary

Add Kubernetes Resources Documentation Generator Tool

Overview

This PR introduces a new tool for generating and listing Kubernetes resources documentation from OpenAPI specification files. It includes a new CLI command and several supporting packages for processing Kubernetes configurations and OpenAPI specs.

Change Types

Type Description
Feature New CLI command to list Kubernetes resources
Feature New packages for configuration loading and OpenAPI processing
Test Test coverage for API version handling and OpenAPI spec loading

Affected Modules

Module / File Change Description
gen-resourcesdocs/cmd/cli/resourceslist.go New CLI command to list resources from a spec file
gen-resourcesdocs/pkg/config/categories.go New structures for loading field categories from YAML
gen-resourcesdocs/pkg/kubernetes/ New package with API version handling, properties and extensions
gen-resourcesdocs/pkg/openapi/ New package for loading OpenAPI specifications from JSON

Notes for Reviewers

  • Please check the error messages in extensions.go as there's a typo where "kubernetes" is misspelled as "bubernetes"
  • Verify that the OpenAPI spec loader correctly handles the 617 definitions mentioned in the test

zhzhuang-zju and others added 25 commits March 17, 2025 20:23
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
add gen-resourcesdocs to generate API docs
Signed-off-by: RainbowMango <qdurenhongcai@gmail.com>
…en_cluster_modes

Explain the difference between Push and Pull mode in details
Signed-off-by: Arhell <arhell333@gmail.com>
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
improve document-releasing process
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
Signed-off-by: 宋阳 <songyang2@xiaohongshu.com>
update install-binary.md to adjust the installation order
Signed-off-by: changzhen <changzhen5@huawei.com>
…or-components

Add binding address configuration for security considerations
Signed-off-by: changzhen <changzhen5@huawei.com>
Signed-off-by: Arhell <arhell333@gmail.com>
Signed-off-by: Arhell <arhell333@gmail.com>
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
add karmadactl operation scope docs
Signed-off-by: changzhen <changzhen5@huawei.com>
add more description for op/cop resourceSelectors
Signed-off-by: wei-chenglai <qazwsx0939059006@gmail.com>
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
file := cmd.Flag(fileOption).Value.String()
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Undefined variable 'fileOption' causes runtime panic.

The code references 'fileOption' variable which is not defined in this file, leading to a nil pointer dereference at runtime.

Current Code (Diff):

-			file := cmd.Flag(fileOption).Value.String()
+			file := cmd.Flag("file").Value.String()
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
file := cmd.Flag(fileOption).Value.String()
file := cmd.Flag("file").Value.String()

}
value, ok := extension.(string)
if !ok {
return nil, errors.New("x-bubernetes-patch-strategy is not a string")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-patch-strategy' instead of 'x-kubernetes-patch-strategy', which will cause confusion during debugging.

Current Code (Diff):

-		return nil, errors.New("x-bubernetes-patch-strategy is not a string")
+		return nil, errors.New("x-kubernetes-patch-strategy is not a string")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-patch-strategy is not a string")
return nil, errors.New("x-kubernetes-patch-strategy is not a string")

}
value, ok := extension.(string)
if !ok {
return nil, errors.New("x-bubernetes-patch-merge-key is not a string")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-patch-merge-key' instead of 'x-kubernetes-patch-merge-key', which will cause confusion during debugging.

Current Code (Diff):

-		return nil, errors.New("x-bubernetes-patch-merge-key is not a string")
+		return nil, errors.New("x-kubernetes-patch-merge-key is not a string")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-patch-merge-key is not a string")
return nil, errors.New("x-kubernetes-patch-merge-key is not a string")

}
value, ok := extension.(string)
if !ok {
return nil, errors.New("x-bubernetes-list-type is not a string")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-list-type' instead of 'x-kubernetes-list-type', which will cause confusion during debugging.

Current Code (Diff):

-		return nil, errors.New("x-bubernetes-list-type is not a string")
+		return nil, errors.New("x-kubernetes-list-type is not a string")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-list-type is not a string")
return nil, errors.New("x-kubernetes-list-type is not a string")

}
value, ok := extension.([]interface{})
if !ok {
return nil, errors.New("x-bubernetes-list-map-keys is not an array")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-list-map-keys' instead of 'x-kubernetes-list-map-keys', which will cause confusion during debugging.

Current Code (Diff):

-		return nil, errors.New("x-bubernetes-list-map-keys is not an array")
+		return nil, errors.New("x-kubernetes-list-map-keys is not an array")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-list-map-keys is not an array")
return nil, errors.New("x-kubernetes-list-map-keys is not an array")

for _, val := range value {
v, ok := val.(string)
if !ok {
return nil, errors.New("x-bubernetes-list-map-keys value is not a string")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-list-map-keys' instead of 'x-kubernetes-list-map-keys', which will cause confusion during debugging.

Current Code (Diff):

-			return nil, errors.New("x-bubernetes-list-map-keys value is not a string")
+			return nil, errors.New("x-kubernetes-list-map-keys value is not a string")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-list-map-keys value is not a string")
return nil, errors.New("x-kubernetes-list-map-keys value is not a string")

}
value, ok := extension.(string)
if !ok {
return nil, errors.New("x-bubernetes-action is not a string")
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Critical typo in error message.

Error message references 'x-bubernetes-action' instead of 'x-kubernetes-action', which will cause confusion during debugging.

Current Code (Diff):

-		return nil, errors.New("x-bubernetes-action is not a string")
+		return nil, errors.New("x-kubernetes-action is not a string")
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
return nil, errors.New("x-bubernetes-action is not a string")
return nil, errors.New("x-kubernetes-action is not a string")

🔄 Dependencies Affected

infra/gen-resourcesdocs/pkg/kubernetes/actions.go

Function: Actions.Add

Issue: This function calls getActionExtension which has an incorrect error message

Suggestion: No change needed in the dependency, just fix the error message in the current file


return value, nil
}

panic(fmt.Errorf("No type found for object %v", s))
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Application Crash Risk: Panic in GetTypeNameAndKey().

Using panic() will cause the application to crash unexpectedly when encountering unknown schema types, which should be handled with error returns instead.

Current Code (Diff):

-	panic(fmt.Errorf("No type found for object %v", s))
+	return "", nil, fmt.Errorf("No type found for object %v", s)
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
panic(fmt.Errorf("No type found for object %v", s))
return "", nil, fmt.Errorf("No type found for object %v", s)

// primitive types.
func GetTypeNameAndKey(s spec.Schema) (string, *Key) {
if isMap(s) {
typ, key := GetTypeNameAndKey(*s.AdditionalProperties.Schema)
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Potential Nil Pointer Dereference in Schema Access.

Accessing s.AdditionalProperties.Schema without nil check could cause runtime panic if Schema is nil, even though AdditionalProperties is verified non-nil.

Current Code (Diff):

-		typ, key := GetTypeNameAndKey(*s.AdditionalProperties.Schema)
+		if s.AdditionalProperties.Schema == nil {
+			return "map[string]interface{}", nil
+		}
+		typ, key := GetTypeNameAndKey(*s.AdditionalProperties.Schema)
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
typ, key := GetTypeNameAndKey(*s.AdditionalProperties.Schema)
if s.AdditionalProperties.Schema == nil {
return "map[string]interface{}", nil
}
typ, key := GetTypeNameAndKey(*s.AdditionalProperties.Schema)


// Recurse if type is array
if isArray(s) {
typ, key := GetTypeNameAndKey(*s.Items.Schema)
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Potential Nil Pointer Dereference in Array Items Schema.

Accessing s.Items.Schema without nil check could cause runtime panic if Schema is nil, even though isArray confirms the type is array.

Current Code (Diff):

-		typ, key := GetTypeNameAndKey(*s.Items.Schema)
+		if s.Items.Schema == nil {
+			return "[]interface{}", nil
+		}
+		typ, key := GetTypeNameAndKey(*s.Items.Schema)
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
typ, key := GetTypeNameAndKey(*s.Items.Schema)
if s.Items.Schema == nil {
return "[]interface{}", nil
}
typ, key := GetTypeNameAndKey(*s.Items.Schema)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants