-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use deployment for sentinel (#36)
* rebase * rebase * rebase * feat: use deployment for sentinel * support crud for deployment * rebase * tmp * tmp * tmp * tmp * tmp * remove log and update the resource requirement * update readme * add sentinelConfig * test done * remove println * add sentinel.yaml * tmp * update * e2e test done * update --------- Co-authored-by: Colin Chamber <[email protected]>
- Loading branch information
1 parent
4d7cd87
commit e51f365
Showing
20 changed files
with
638 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,4 +122,4 @@ rules: | |
- list | ||
- patch | ||
- update | ||
- watch | ||
- watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -993,7 +993,6 @@ spec: | |
type: string | ||
required: | ||
- image | ||
- master | ||
- password | ||
- replicas | ||
- resources | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: kvrocks.com/v1alpha1 | ||
kind: KVRocks | ||
metadata: | ||
name: sentinel-1 | ||
namespace: kvrocks | ||
spec: | ||
image: redis:6.2.4 | ||
imagePullPolicy: IfNotPresent | ||
replicas: 3 | ||
password: c4ca4238a0b923820dcc509a6f75849b | ||
type: sentinel | ||
toleration: | ||
- key: kvrocks | ||
effect: NoSchedule | ||
operator: Exists | ||
- key: node | ||
effect: NoSchedule | ||
operator: Exists | ||
resources: | ||
limits: | ||
cpu: 500m | ||
memory: 500Mi | ||
requests: | ||
cpu: 500m | ||
memory: 500Mi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package k8s | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func (c *Client) CreateIfNotExistsDeployment(deployment *appsv1.Deployment) error { | ||
if err := c.client.Create(ctx, deployment); err != nil && !errors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
c.logger.V(1).Info("create deployment successfully", "deployment", deployment.Name) | ||
return nil | ||
} | ||
|
||
func (c *Client) GetDeployment(key types.NamespacedName) (*appsv1.Deployment, error) { | ||
var deployment appsv1.Deployment | ||
if err := c.client.Get(ctx, key, &deployment); err != nil { | ||
return nil, err | ||
} | ||
return &deployment, nil | ||
} | ||
|
||
func (c *Client) UpdateDeployment(deployment *appsv1.Deployment) error { | ||
if err := c.client.Update(ctx, deployment); err != nil { | ||
return err | ||
} | ||
c.logger.V(1).Info("update deployment successfully", "deployment", deployment.Name) | ||
return nil | ||
} | ||
|
||
func (c *Client) ListDeploymentPods(key types.NamespacedName) (*corev1.PodList, error) { | ||
deployment, err := c.GetDeployment(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
labels := make(map[string]string) | ||
for k, v := range deployment.Spec.Selector.MatchLabels { | ||
labels[k] = v | ||
} | ||
var pods corev1.PodList | ||
if err := c.client.List(ctx, &pods, client.InNamespace(deployment.Namespace), client.MatchingLabels(labels)); err != nil { | ||
return nil, err | ||
} | ||
return &pods, nil | ||
} |
Oops, something went wrong.