Skip to content

Commit

Permalink
fix crd util (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer authored Mar 26, 2020
1 parent 66b918e commit 61be897
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 7 deletions.
30 changes: 30 additions & 0 deletions docs/api-references/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5339,6 +5339,16 @@ <h3 id="pingcap.com/v1alpha1.PDStatus">PDStatus
<td>
</td>
</tr>
<tr>
<td>
<code>image</code></br>
<em>
string
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="pingcap.com/v1alpha1.PDStoreLabel">PDStoreLabel
Expand Down Expand Up @@ -8054,6 +8064,16 @@ <h3 id="pingcap.com/v1alpha1.TiDBStatus">TiDBStatus
<td>
</td>
</tr>
<tr>
<td>
<code>image</code></br>
<em>
string
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="pingcap.com/v1alpha1.TiDBTLSClient">TiDBTLSClient
Expand Down Expand Up @@ -11338,6 +11358,16 @@ <h3 id="pingcap.com/v1alpha1.TiKVStatus">TiKVStatus
<td>
</td>
</tr>
<tr>
<td>
<code>image</code></br>
<em>
string
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="pingcap.com/v1alpha1.TiKVStorageConfig">TiKVStorageConfig
Expand Down
6 changes: 3 additions & 3 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: tidbclusters.pingcap.com
spec:
additionalPrinterColumns:
- JSONPath: .spec.pd.image
- JSONPath: .status.pd.image
description: The image for PD cluster
name: PD
type: string
Expand All @@ -22,7 +22,7 @@ spec:
description: The desired replicas number of PD cluster
name: Desire
type: integer
- JSONPath: .spec.tikv.image
- JSONPath: .status.tikv.image
description: The image for TiKV cluster
name: TiKV
type: string
Expand All @@ -38,7 +38,7 @@ spec:
description: The desired replicas number of TiKV cluster
name: Desire
type: integer
- JSONPath: .spec.tidb.image
- JSONPath: .status.tidb.image
description: The image for TiDB cluster
name: TiDB
type: string
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ type PDStatus struct {
Leader PDMember `json:"leader,omitempty"`
FailureMembers map[string]PDFailureMember `json:"failureMembers,omitempty"`
UnjoinedMembers map[string]UnjoinedMember `json:"unjoinedMembers,omitempty"`
Image string `json:"image,omitempty"`
}

// PDMember is PD member
Expand Down Expand Up @@ -550,6 +551,7 @@ type TiDBStatus struct {
Members map[string]TiDBMember `json:"members,omitempty"`
FailureMembers map[string]TiDBFailureMember `json:"failureMembers,omitempty"`
ResignDDLOwnerRetryCount int32 `json:"resignDDLOwnerRetryCount,omitempty"`
Image string `json:"image,omitempty"`
}

// TiDBMember is TiDB member
Expand All @@ -576,6 +578,7 @@ type TiKVStatus struct {
Stores map[string]TiKVStore `json:"stores,omitempty"`
TombstoneStores map[string]TiKVStore `json:"tombstoneStores,omitempty"`
FailureStores map[string]TiKVFailureStore `json:"failureStores,omitempty"`
Image string `json:"image,omitempty"`
}

// TiKVStores is either Up/Down/Offline/Tombstone
Expand Down
5 changes: 5 additions & 0 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ func (pmm *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set
tc.Status.PD.Synced = true
tc.Status.PD.Members = pdStatus
tc.Status.PD.Leader = tc.Status.PD.Members[leader.GetName()]
tc.Status.PD.Image = ""
c := filterContainer(set, "pd")
if c != nil {
tc.Status.PD.Image = c.Image
}

// k8s check
err = pmm.collectUnjoinedMembers(tc, set, pdStatus)
Expand Down
6 changes: 5 additions & 1 deletion pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,11 @@ func (tmm *tidbMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, se
tidbStatus[name] = newTidbMember
}
tc.Status.TiDB.Members = tidbStatus

tc.Status.TiDB.Image = ""
c := filterContainer(set, "tidb")
if c != nil {
tc.Status.TiDB.Image = c.Image
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ func (tkmm *tikvMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, s
tc.Status.TiKV.Synced = true
tc.Status.TiKV.Stores = stores
tc.Status.TiKV.TombstoneStores = tombstoneStores
tc.Status.TiKV.Image = ""
c := filterContainer(set, "tikv")
if c != nil {
tc.Status.TiKV.Image = c.Image
}
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/manager/member/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"

"github.com/BurntSushi/toml"
"github.com/pingcap/advanced-statefulset/pkg/apis/apps/v1/helper"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
Expand Down Expand Up @@ -310,3 +311,13 @@ func updateStatefulSet(setCtl controller.StatefulSetControlInterface, tc *v1alph
func clusterSecretName(tc *v1alpha1.TidbCluster, component string) string {
return fmt.Sprintf("%s-%s-cluster-secret", tc.Name, component)
}

// filter targetContainer by containerName, If not find, then return nil
func filterContainer(sts *apps.StatefulSet, containerName string) *corev1.Container {
for _, c := range sts.Spec.Template.Spec.Containers {
if c.Name == containerName {
return &c
}
}
return nil
}
6 changes: 3 additions & 3 deletions pkg/util/crdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
Name: "PD",
Type: "string",
Description: "The image for PD cluster",
JSONPath: ".spec.pd.image",
JSONPath: ".status.pd.image",
}
tidbClusterPDStorageColumn = extensionsobj.CustomResourceColumnDefinition{
Name: "Storage",
Expand All @@ -52,7 +52,7 @@ var (
Name: "TiKV",
Type: "string",
Description: "The image for TiKV cluster",
JSONPath: ".spec.tikv.image",
JSONPath: ".status.tikv.image",
}
tidbClusterTiKVStorageColumn = extensionsobj.CustomResourceColumnDefinition{
Name: "Storage",
Expand All @@ -76,7 +76,7 @@ var (
Name: "TiDB",
Type: "string",
Description: "The image for TiDB cluster",
JSONPath: ".spec.tidb.image",
JSONPath: ".status.tidb.image",
}
tidbClusterTiDBReadyColumn = extensionsobj.CustomResourceColumnDefinition{
Name: "Ready",
Expand Down

0 comments on commit 61be897

Please sign in to comment.