Compare commits
16 Commits
cli/fix/up
...
module-app
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33301f7e7b | ||
|
|
2063cb30d4 | ||
|
|
92acb619d0 | ||
|
|
8bf086b639 | ||
|
|
6642c2ad2f | ||
|
|
97a504d91f | ||
|
|
e8f30989f3 | ||
|
|
2f5a3c322d | ||
|
|
cce4a36583 | ||
|
|
2471def663 | ||
|
|
e04eaa4d1b | ||
|
|
421d2e9f6e | ||
|
|
8dd5f37f53 | ||
|
|
a8a14ab9d6 | ||
|
|
4b7a1d9925 | ||
|
|
870cd164f9 |
@@ -170,7 +170,7 @@ spec:
|
|||||||
priorityClassName: "system-cluster-critical"
|
priorityClassName: "system-cluster-critical"
|
||||||
containers:
|
containers:
|
||||||
- name: app-service
|
- name: app-service
|
||||||
image: beclab/app-service:0.4.60
|
image: beclab/app-service:0.4.61
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
securityContext:
|
securityContext:
|
||||||
runAsUser: 0
|
runAsUser: 0
|
||||||
|
|||||||
@@ -570,36 +570,9 @@ func (h *Handler) validateArgoResources(ctx context.Context, req *admissionv1.Ad
|
|||||||
return h.sidecarWebhook.AdmissionError(req.UID, err)
|
return h.sidecarWebhook.AdmissionError(req.UID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := object.GetLabels()
|
|
||||||
if labels != nil && labels[constants.ApplicationAuthorLabel] == constants.ByteTradeAuthor {
|
|
||||||
return resp
|
|
||||||
}
|
|
||||||
|
|
||||||
appNamespace := req.Namespace
|
appNamespace := req.Namespace
|
||||||
if strings.HasSuffix(req.Namespace, "-shared") {
|
if !apputils.IsProtectedNamespace(appNamespace) {
|
||||||
var ns corev1.Namespace
|
return resp
|
||||||
err := h.ctrlClient.Get(ctx, types.NamespacedName{Name: req.Namespace}, &ns)
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("failed to get ns %s %v", req.Namespace, err)
|
|
||||||
return h.sidecarWebhook.AdmissionError(req.UID, err)
|
|
||||||
}
|
|
||||||
if ns.Labels != nil {
|
|
||||||
installUser := ns.Labels[constants.ApplicationInstallUserLabel]
|
|
||||||
appName := ns.Labels[constants.ApplicationNameLabel]
|
|
||||||
appNamespace = fmt.Sprintf("%s-%s", appName, installUser)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the namespace matches some ApplicationManager.Spec.AppNamespace
|
|
||||||
var amList v1alpha1.ApplicationManagerList
|
|
||||||
if err := h.ctrlClient.List(ctx, &amList, &client.ListOptions{}); err != nil {
|
|
||||||
klog.Errorf("Failed to list application managers for argo resources validation err=%v", err)
|
|
||||||
return h.sidecarWebhook.AdmissionError(req.UID, err)
|
|
||||||
}
|
|
||||||
for _, am := range amList.Items {
|
|
||||||
if am.Spec.AppNamespace == appNamespace {
|
|
||||||
return resp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Allowed = false
|
resp.Allowed = false
|
||||||
|
|||||||
@@ -199,13 +199,13 @@ func (h *HelmOps) AddApplicationLabelsToDeployment() error {
|
|||||||
patch = string(patchByte)
|
patch = string(patchByte)
|
||||||
|
|
||||||
// TODO: add ownerReferences of user
|
// TODO: add ownerReferences of user
|
||||||
deployment, err := k8s.AppsV1().Deployments(h.app.Namespace).Get(h.ctx, h.app.RawAppName, metav1.GetOptions{})
|
deployment, err := k8s.AppsV1().Deployments(h.app.Namespace).Get(h.ctx, h.app.AppName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
return h.tryToAddApplicationLabelsToStatefulSet(k8s, patch)
|
return h.tryToAddApplicationLabelsToStatefulSet(k8s, patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.Errorf("Failed to get deployment %s in namespace %s: %v", h.app.RawAppName, h.app.Namespace, err)
|
klog.Errorf("Failed to get deployment %s in namespace %s: %v", h.app.AppName, h.app.Namespace, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ func (h *HelmOps) AddApplicationLabelsToDeployment() error {
|
|||||||
metav1.PatchOptions{})
|
metav1.PatchOptions{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to patch deployment %s in namespace %s: %v", h.app.RawAppName, h.app.Namespace, err)
|
klog.Errorf("Failed to patch deployment %s in namespace %s: %v", h.app.AppName, h.app.Namespace, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -278,13 +278,13 @@ func (h *HelmOps) tryToAddApplicationLabelsToCluster() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *HelmOps) tryToAddApplicationLabelsToStatefulSet(k8s *kubernetes.Clientset, patch string) error {
|
func (h *HelmOps) tryToAddApplicationLabelsToStatefulSet(k8s *kubernetes.Clientset, patch string) error {
|
||||||
statefulSet, err := k8s.AppsV1().StatefulSets(h.app.Namespace).Get(h.ctx, h.app.RawAppName, metav1.GetOptions{})
|
statefulSet, err := k8s.AppsV1().StatefulSets(h.app.Namespace).Get(h.ctx, h.app.AppName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.Errorf("Failed to get statefulset %s in namespace %s: %v", h.app.RawAppName, h.app.Namespace, err)
|
klog.Errorf("Failed to get statefulset %s in namespace %s: %v", h.app.AppName, h.app.Namespace, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,7 +585,7 @@ func (h *HelmOps) isStartUp() (bool, error) {
|
|||||||
func (h *HelmOps) findAppSelectedPods() (*corev1.PodList, error) {
|
func (h *HelmOps) findAppSelectedPods() (*corev1.PodList, error) {
|
||||||
var labelSelector string
|
var labelSelector string
|
||||||
deployment, err := h.client.KubeClient.Kubernetes().AppsV1().Deployments(h.app.Namespace).
|
deployment, err := h.client.KubeClient.Kubernetes().AppsV1().Deployments(h.app.Namespace).
|
||||||
Get(h.ctx, h.app.RawAppName, metav1.GetOptions{})
|
Get(h.ctx, h.app.AppName, metav1.GetOptions{})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
labelSelector = metav1.FormatLabelSelector(deployment.Spec.Selector)
|
labelSelector = metav1.FormatLabelSelector(deployment.Spec.Selector)
|
||||||
@@ -593,7 +593,7 @@ func (h *HelmOps) findAppSelectedPods() (*corev1.PodList, error) {
|
|||||||
|
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
sts, err := h.client.KubeClient.Kubernetes().AppsV1().StatefulSets(h.app.Namespace).
|
sts, err := h.client.KubeClient.Kubernetes().AppsV1().StatefulSets(h.app.Namespace).
|
||||||
Get(h.ctx, h.app.RawAppName, metav1.GetOptions{})
|
Get(h.ctx, h.app.AppName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -603,7 +603,7 @@ func (h *HelmOps) findAppSelectedPods() (*corev1.PodList, error) {
|
|||||||
List(h.ctx, metav1.ListOptions{LabelSelector: labelSelector})
|
List(h.ctx, metav1.ListOptions{LabelSelector: labelSelector})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("app %s get pods err %v", h.app.RawAppName, err)
|
klog.Errorf("app %s get pods err %v", h.app.AppName, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return pods, nil
|
return pods, nil
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ func (p *SuspendingApp) Exec(ctx context.Context) (StatefulInProgressApp, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *SuspendingApp) exec(ctx context.Context) error {
|
func (p *SuspendingApp) exec(ctx context.Context) error {
|
||||||
|
err := suspendOrResumeApp(ctx, p.client, p.manager, int32(0))
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("suspend %s %s failed %v", p.manager.Spec.Type, p.manager.Spec.AppName, err)
|
||||||
|
return fmt.Errorf("suspend app %s failed %w", p.manager.Spec.AppName, err)
|
||||||
|
}
|
||||||
// If stop-all is requested, also stop v2 server-side shared charts by scaling them down
|
// If stop-all is requested, also stop v2 server-side shared charts by scaling them down
|
||||||
if p.manager.Annotations[api.AppStopAllKey] == "true" {
|
if p.manager.Annotations[api.AppStopAllKey] == "true" {
|
||||||
var appCfg *appcfg.ApplicationConfig
|
var appCfg *appcfg.ApplicationConfig
|
||||||
@@ -104,12 +109,6 @@ func (p *SuspendingApp) exec(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
err := suspendOrResumeApp(ctx, p.client, p.manager, int32(0))
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("suspend %s %s failed %v", p.manager.Spec.Type, p.manager.Spec.AppName, err)
|
|
||||||
return fmt.Errorf("suspend app %s failed %w", p.manager.Spec.AppName, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.manager.Spec.Type == appsv1.Middleware && userspace.IsKbMiddlewares(p.manager.Spec.AppName) {
|
if p.manager.Spec.Type == appsv1.Middleware && userspace.IsKbMiddlewares(p.manager.Spec.AppName) {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func suspendOrResumeApp(ctx context.Context, cli client.Client, am *appv1alpha1.
|
|||||||
workloadName := ""
|
workloadName := ""
|
||||||
switch workload := w.(type) {
|
switch workload := w.(type) {
|
||||||
case *appsv1.Deployment:
|
case *appsv1.Deployment:
|
||||||
if check(am.Spec.RawAppName, workload.Name) {
|
if check(am.Spec.AppName, workload.Name) {
|
||||||
if workload.Annotations == nil {
|
if workload.Annotations == nil {
|
||||||
workload.Annotations = make(map[string]string)
|
workload.Annotations = make(map[string]string)
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ func suspendOrResumeApp(ctx context.Context, cli client.Client, am *appv1alpha1.
|
|||||||
workloadName = workload.Namespace + "/" + workload.Name
|
workloadName = workload.Namespace + "/" + workload.Name
|
||||||
}
|
}
|
||||||
case *appsv1.StatefulSet:
|
case *appsv1.StatefulSet:
|
||||||
if check(am.Spec.RawAppName, workload.Name) {
|
if check(am.Spec.AppName, workload.Name) {
|
||||||
if workload.Annotations == nil {
|
if workload.Annotations == nil {
|
||||||
workload.Annotations = make(map[string]string)
|
workload.Annotations = make(map[string]string)
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ func isStartUp(am *appv1alpha1.ApplicationManager, cli client.Client) (bool, err
|
|||||||
var labelSelector string
|
var labelSelector string
|
||||||
var deployment appsv1.Deployment
|
var deployment appsv1.Deployment
|
||||||
|
|
||||||
err := cli.Get(context.TODO(), types.NamespacedName{Name: am.Spec.RawAppName, Namespace: am.Spec.AppNamespace}, &deployment)
|
err := cli.Get(context.TODO(), types.NamespacedName{Name: am.Spec.AppName, Namespace: am.Spec.AppNamespace}, &deployment)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
labelSelector = metav1.FormatLabelSelector(deployment.Spec.Selector)
|
labelSelector = metav1.FormatLabelSelector(deployment.Spec.Selector)
|
||||||
@@ -209,7 +209,7 @@ func isStartUp(am *appv1alpha1.ApplicationManager, cli client.Client) (bool, err
|
|||||||
|
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
var sts appsv1.StatefulSet
|
var sts appsv1.StatefulSet
|
||||||
err = cli.Get(context.TODO(), types.NamespacedName{Name: am.Spec.RawAppName, Namespace: am.Spec.AppNamespace}, &sts)
|
err = cli.Get(context.TODO(), types.NamespacedName{Name: am.Spec.AppName, Namespace: am.Spec.AppNamespace}, &sts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user