Skip to content
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

feat: add resourcetopo package #43

Merged
merged 1 commit into from
Apr 9, 2024
Merged

Conversation

AnnaYue
Copy link
Collaborator

@AnnaYue AnnaYue commented Mar 29, 2024

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

2. What is the scope of this PR (e.g. component or file name):

resourcetopo/

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@AnnaYue AnnaYue force-pushed the main branch 2 times, most recently from 0372f37 to 602327f Compare April 1, 2024 07:44
@AnnaYue AnnaYue changed the title [WIP] feat: add resourcetopo package feat: add resourcetopo package Apr 1, 2024
@AnnaYue AnnaYue force-pushed the main branch 3 times, most recently from f8aaeb8 to f583250 Compare April 2, 2024 07:27
return m.storages[key]
}

func (m *manager) createVirtualStorage(object metav1.TypeMeta) (*nodeStorage, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change object to meta, or keep them consistent?

return s, nil
}

informer := getInformer(typeMeta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check whether getInfomer is nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add nil check in manager call func

return s, nil
}

func (m *manager) AddRelationHandler(preOrder, postOrder metav1.TypeMeta, handler RelationHandler) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can add some comments for those key methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added in types interface define

return m, nil
}

func (m *manager) AddConfig(cfg Config) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

addConfig may be more safety.

s.preOrderResources = make(map[string]*nodeStorage)
}
key := generateMetaKey(preOrder)
preStorage := s.manager.storages[key]
Copy link
Collaborator

Choose a reason for hiding this comment

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

s.manager.getStorage

}

func (m *manager) AddTopologyConfig(cfg TopologyConfig) error {
if cfg.GetInformer == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking GetInformer in getOrCreateStorage is better?

return nil
}

func (m *manager) GetNode(meta *metav1.TypeMeta, name *types.NamespacedName) (NodeInfo, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

*metav1.TypeMeta
->
metav1.TypeMeta

Signatures can be the same.

relationEventQueue chan relationEvent
nodeEventQueue chan nodeEvent
configLock sync.Mutex
startedCh chan struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really used? Or use started bool instead?

storageRef: s,
name: name,
namespace: namespace,
// for virtual resource, its lifecycle handled by resourcetopo
Copy link
Collaborator

Choose a reason for hiding this comment

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

For virtual resource whose lifecycle is handled by resourcetopo


var _ TopoNodeStorage = &nodeStorage{}

type nodeStorage struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is possible to add some annotations to key data.

func (s *nodeStorage) OnAdd(obj interface{}) {
topoObject, ok := obj.(Object)
if !ok {
klog.Errorf("Failed to transform to k8s object %v, ignore this update nodeEvent", obj)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Case can be used in a consistent.

}
}

func (s *nodeStorage) GetNode(namespacedName *types.NamespacedName) (NodeInfo, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When use namespace and name, and when use NamespacedName?

)

var (
ReplicaSetMeta = metav1.TypeMeta{Kind: "ReplicaSet", APIVersion: "apps/v1"}
Copy link
Collaborator

@shaofan-hs shaofan-hs Apr 9, 2024

Choose a reason for hiding this comment

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

Use full name or short name in the same? Full name is easier to read :)

cancel()
})

It("single pod add", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Single pod added or Add single pod?

PreMeta: StsMeta,
PostMetas: []metav1.TypeMeta{PodMeta},
Resolve: func(preOrder Object) []ResourceRelation {
stsObj := preOrder.(*appsv1.StatefulSet)
Copy link
Collaborator

@shaofan-hs shaofan-hs Apr 9, 2024

Choose a reason for hiding this comment

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

It is safer to check ok.

1. support kubernetes or kubernetes likely resources topology management;
2. support add node event handler for node info changed;
3. support add relation event handler for relation existence changed;
@shaofan-hs shaofan-hs merged commit 249890d into KusionStack:main Apr 9, 2024
5 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants