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

fix: find workload spec.replicas #1462

Merged
merged 1 commit into from
Dec 19, 2023
Merged

Conversation

0xgj
Copy link
Contributor

@0xgj 0xgj commented Nov 29, 2023

Ⅰ. Describe what this PR does

fix get spec.replicas from unstructured object.

Ⅱ. Does this pull request fix one issue?

unstructured.NestedInt64(obj, "spec.replicas") can not get replicas from like:

apiVersion: apps.tkestack.io/v1
kind: TApp
metadata:
  annotations:
    kruise.io/auto-generate-persistent-pod-state: "true"
    kruise.io/preferred-persistent-topology: kubernetes.io/hostname
  creationTimestamp: "2023-11-28T14:25:14Z"
  generation: 6
  labels:
    app: example-tapp
  name: example-tapp
  namespace: kruise-system
  resourceVersion: "226631180"
  selfLink: /apis/apps.tkestack.io/v1/namespaces/kruise-system/tapps/example-tapp
  uid: a6c71435-b382-489c-ab5a-f55cc7de0a28
spec:
  defaultTemplateName: default
  replicas: 2
  selector:
    matchLabels:
      app: example-tapp

Ⅲ. Describe how to verify it

test it use TApp https://github.com/tkestack/tapp.

  1. install TApp operator;
  2. use TApp above, add annotations kruise.io/auto-generate-persistent-pod-state: "true", kruise.io/preferred-persistent-topology: kubernetes.io/hostname
  3. get ersistentpodstates
apiVersion: apps.kruise.io/v1alpha1
kind: PersistentPodState
metadata:
  creationTimestamp: "2023-11-28T14:25:14Z"
  generation: 1
  name: example-tapp
  namespace: kruise-system
  ownerReferences:
  - apiVersion: apps.tkestack.io/v1
    controller: true
    kind: TApp
    name: example-tapp
    uid: a6c71435-b382-489c-ab5a-f55cc7de0a28
  resourceVersion: "226654296"
  selfLink: /apis/apps.kruise.io/v1alpha1/namespaces/kruise-system/persistentpodstates/example-tapp
  uid: 9484791e-ee7f-46bb-a659-39ea859fbd6c
spec:
  preferredPersistentTopology:
  - preference:
      nodeTopologyKeys:
      - kubernetes.io/hostname
    weight: 100
  targetRef:
    apiVersion: apps.tkestack.io/v1
    kind: TApp
    name: example-tapp
status:
  observedGeneration: 1
  podStates:
    example-tapp-0:
      nodeName: 9.134.111.49
      nodeTopologyLabels:
        kubernetes.io/hostname: 9.134.111.49
    example-tapp-1:
      nodeName: 9.134.111.49
      nodeTopologyLabels:
        kubernetes.io/hostname: 9.134.111.49
  1. delete pod example-tapp-0 and recreate example-tapp-0, get pod yam, nodeAffinity injectedl:
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kruise.io/injected-persistent-pod-state: example-tapp
  creationTimestamp: "2023-11-29T02:36:55Z"
  generateName: example-tapp-
  labels:
    app: example-tapp
    tapp_instance_key: "0"
    tapp_template_hash_key: "506133740347201105"
    tapp_uniq_hash_key: "6441391112236715516"
  name: example-tapp-0
  namespace: default
  ownerReferences:
  - apiVersion: apps.tkestack.io/v1
    controller: true
    kind: TApp
    name: example-tapp
    uid: 5c50a01a-5940-49bb-9a17-f2f516aabf08
  resourceVersion: "226693884"
  selfLink: /api/v1/namespaces/default/pods/example-tapp-0
  uid: d6545108-abd2-4ef5-b7a7-e67102145cd6
spec:
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - 9.134.111.49
        weight: 100
  containers:
  - command:
    - sleep
    - "3600"
    image: nginx:1.7.9
    imagePullPolicy: IfNotPresent
    name: nginx1
    resources:

Ⅳ. Special notes for reviews

@kruise-bot
Copy link

Welcome @0xgj! It looks like this is your first PR to openkruise/kruise 🎉

@kruise-bot kruise-bot added the size/M size/M: 30-99 label Nov 29, 2023
@0xgj 0xgj changed the title fix: find spec.replicas workload fix: find workload spec.replicas Nov 29, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 29, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (fa9a9a0) 48.30% compared to head (0f407db) 47.34%.

Files Patch % Lines
pkg/util/controllerfinder/controller_finder.go 75.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1462      +/-   ##
==========================================
- Coverage   48.30%   47.34%   -0.97%     
==========================================
  Files         154      156       +2     
  Lines       21667    22150     +483     
==========================================
+ Hits        10467    10487      +20     
- Misses      10048    10514     +466     
+ Partials     1152     1149       -3     
Flag Coverage Δ
unittests 47.34% <75.00%> (-0.97%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@0xgj
Copy link
Contributor Author

0xgj commented Nov 29, 2023

/test

@0xgj 0xgj closed this Nov 29, 2023
@0xgj 0xgj reopened this Nov 29, 2023
@0xgj
Copy link
Contributor Author

0xgj commented Nov 29, 2023

/assign @furykerry

@ls-2018
Copy link
Member

ls-2018 commented Dec 11, 2023

@0xgj please use git commit -s -m resubmit, solve DCO problem.

@ls-2018
Copy link
Member

ls-2018 commented Dec 11, 2023

/lgtm

@0xgj
Copy link
Contributor Author

0xgj commented Dec 11, 2023

@0xgj please use git commit -s -m resubmit, solve DCO problem.

done @ls-2018

@ls-2018
Copy link
Member

ls-2018 commented Dec 12, 2023

/lgtm

@0xgj
Copy link
Contributor Author

0xgj commented Dec 19, 2023

@furykerry can you help merge this commit?

@zmberg
Copy link
Member

zmberg commented Dec 19, 2023

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zmberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kruise-bot kruise-bot merged commit 1f7f06f into openkruise:master Dec 19, 2023
25 checks passed
@zmberg zmberg added this to the 1.6 milestone Mar 7, 2024
ppbits pushed a commit to ppbits/kruise that referenced this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants