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

sync CN store information to CNSet status #384

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/core/v1alpha1/cnset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const (
CNRoleAP CNRole = "AP"
)

const (
CNStoreStateUnknown string = "Unknown"
)

type CNSetSpec struct {
PodSet `json:",inline"`

Expand Down Expand Up @@ -73,10 +77,18 @@ type CNLabel struct {
type CNSetStatus struct {
ConditionalStatus `json:",inline"`

Stores []CNStore `json:"stores,omitempty"`

Replicas int32 `json:"replicas,omitempty"`
LabelSelector string `json:"labelSelector,omitempty"`
}

type CNStore struct {
UUID string `json:"uuid,omitempty"`
PodName string `json:"podName,omitempty"`
State string `json:"state,omitempty"`
}

type CNSetDeps struct {
LogSetRef `json:",inline"`
// The DNSet it depends on
Expand All @@ -94,7 +106,7 @@ type CNSetDeps struct {

// A CNSet is a resource that represents a set of MO's CN instances
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector
type CNSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
20 changes: 20 additions & 0 deletions api/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
required:
- spec
Expand All @@ -308,7 +319,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.selector
labelSelectorPath: .status.labelSelector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
cnGroups:
properties:
Expand Down Expand Up @@ -1654,6 +1665,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
webui:
description: Webui is the webui service status
Expand Down
4 changes: 2 additions & 2 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/matrixorigin/controller-runtime/pkg/metrics"
"github.com/matrixorigin/matrixone-operator/api/features"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/bucketclaim"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/cnlabel"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/cnstore"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/common"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/proxyset"
"github.com/matrixorigin/matrixone-operator/pkg/hacli"
Expand Down Expand Up @@ -180,7 +180,7 @@ func main() {
}

if features.DefaultFeatureGate.Enabled(features.CNLabel) {
cnLabelController := cnlabel.NewController(hacli.NewManager(mgr.GetClient(), mgr.GetLogger()))
cnLabelController := cnstore.NewController(hacli.NewManager(mgr.GetClient(), mgr.GetLogger()))
err = cnLabelController.Reconcile(mgr)
exitIf(err, "unable to set up cnlabel controller")
} else {
Expand Down
13 changes: 12 additions & 1 deletion deploy/crds/core.matrixorigin.io_cnsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
required:
- spec
Expand All @@ -308,7 +319,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.selector
labelSelectorPath: .status.labelSelector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
22 changes: 22 additions & 0 deletions deploy/crds/core.matrixorigin.io_matrixoneclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
cnGroups:
properties:
Expand Down Expand Up @@ -1654,6 +1665,17 @@ spec:
replicas:
format: int32
type: integer
stores:
items:
properties:
podName:
type: string
state:
type: string
uuid:
type: string
type: object
type: array
type: object
webui:
description: Webui is the webui service status
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ _Appears in:_
| `cnLabels` _[CNLabel](#cnlabel) array_ | Labels are the CN labels for all the CN stores managed by this CNSet |




#### ConditionalStatus


Expand Down
21 changes: 20 additions & 1 deletion pkg/controllers/cnset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,26 @@ func (c *Actor) Observe(ctx *recon.Context[*v1alpha1.CNSet]) (recon.Action[*v1al
if !equality.Semantic.DeepEqual(origin, cs) {
return c.with(cs).Update, nil
}

// calculate status
var stores []v1alpha1.CNStore
podList := &corev1.PodList{}
err = ctx.List(podList, client.InNamespace(cn.Namespace),
client.MatchingLabels(common.SubResourceLabels(cn)))
if err != nil {
return nil, errors.Wrap(err, "list cn pods")
}
for _, pod := range podList.Items {
uid, err := v1alpha1.GetCNPodUUID(&pod)
if err != nil {
return nil, errors.Wrap(err, "get CN pod uuid")
}
stores = append(stores, v1alpha1.CNStore{
UUID: uid,
PodName: pod.Name,
State: v1alpha1.CNStoreStateUnknown,
})
}
cn.Status.Stores = stores
cn.Status.Replicas = cs.Status.Replicas
cn.Status.LabelSelector = cs.Status.LabelSelector
// sync status from cloneset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package cnlabel
package cnstore

import (
"context"
Expand Down