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

display trait status information with customized style #975

Merged
merged 5 commits into from Feb 4, 2021

Conversation

leejanee
Copy link
Member

@leejanee leejanee commented Jan 29, 2021

  1. support customStatus for status message
  2. implement the status on Application CRD serverside with health check
  3. add common labels for trait and workload check
  4. move customStatus and healthPolicy out of extension

fix #885
part of #877
appName added in context, part of #951

Usage:

apiVersion: core.oam.dev/v1alpha2
kind: WorkloadDefinition
metadata:
  name: worker
  annotations:
    definition.oam.dev/description: "Describes long-running, scalable, containerized services that running at backend. They do NOT have network endpoint to receive external network traffic."
spec:
  definitionRef:
    name: deployments.apps
  status:
    healthPolicy: |
      isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas)
    customStatus: |-
      message: "type: " + context.output.spec.template.spec.containers[0].image + ",\t enemies:" + context.outputs.gameconfig.data.enemies
  extension:
    template: |
      output: {
      	apiVersion: "apps/v1"
      	kind:       "Deployment"
      	spec: {
      		selector: matchLabels: {
      			"app.oam.dev/component": context.name
      		}

      		template: {
      			metadata: labels: {
      				"app.oam.dev/component": context.name
      			}

      			spec: {
      				containers: [{
      					name:  context.name
      					image: parameter.image
      					envFrom: [{
      						configMapRef: name: context.name + "game-config"
      					}]
      					if parameter["cmd"] != _|_ {
      						command: parameter.cmd
      					}
      				}]
      			}
      		}
      	}
      }

      outputs: gameconfig: {
      	apiVersion: "v1"
      	kind:       "ConfigMap"
      	metadata: {
      		name: context.name + "game-config"
      	}
      	data: {
      		enemies: parameter.enemies
      		lives:   parameter.lives
      	}
      }

      parameter: {
      	// +usage=Which image would you like to use for your service
      	// +short=i
      	image: string
      	// +usage=Commands to run in the container
      	cmd?: [...string]
      	lives:   string
      	enemies: string
      }



---
apiVersion: core.oam.dev/v1alpha2
kind: TraitDefinition
metadata:
  name: ingress
spec:
  status:
    customStatus: |-
      message: "type: "+ context.outputs.service.spec.type +",\t clusterIP:"+ context.outputs.service.spec.clusterIP+",\t ports:"+ "\(context.outputs.service.spec.ports[0].port)"+",\t domain"+context.outputs.ingress.spec.rules[0].host
    healthPolicy: |
      isHealth: len(context.outputs.service.spec.clusterIP) > 0
  extension:
    template: |
      parameter: {
        domain: string
        http: [string]: int
      }
      // trait template can have multiple outputs in one trait
      outputs: service: {
        apiVersion: "v1"
        kind: "Service"
        spec: {
          selector:
            app: context.name
          ports: [
            for k, v in parameter.http {
              port: v
              targetPort: v
            }
          ]
        }
      }
      outputs: ingress: {
        apiVersion: "networking.k8s.io/v1beta1"
        kind: "Ingress"
        metadata:
          name: context.name
        spec: {
          rules: [{
            host: parameter.domain
            http: {
              paths: [
                for k, v in parameter.http {
                  path: k
                  backend: {
                    serviceName: context.name
                    servicePort: v
                  }
                }
              ]
            }
          }]
        }
      }
apiVersion: core.oam.dev/v1alpha2
kind: Application
metadata:
  name: application-sample
spec:
  components:
    - name: myweb
      type: worker
      settings:
        image: "busybox"
        cmd:
          - sleep
          - "1000"
        lives: "3"
        enemies: "alien"
      traits:
        - name: ingress
          properties:
            domain: "www.example.com"
            http:
              "/": 80

@codecov
Copy link

codecov bot commented Jan 29, 2021

Codecov Report

Merging #975 (c6847a6) into master (2efeec8) will increase coverage by 0.66%.
The diff coverage is 29.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #975      +/-   ##
==========================================
+ Coverage   37.66%   38.33%   +0.66%     
==========================================
  Files         114      114              
  Lines        9557     9556       -1     
==========================================
+ Hits         3600     3663      +63     
+ Misses       5506     5422      -84     
- Partials      451      471      +20     
Flag Coverage Δ
unittests 38.33% <29.24%> (+0.66%) ⬆️

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

Impacted Files Coverage Δ
pkg/builtin/build/build.go 12.35% <0.00%> (ø)
pkg/commands/capability.go 0.00% <0.00%> (ø)
pkg/commands/dashboard.go 0.00% <0.00%> (ø)
pkg/commands/init.go 0.00% <0.00%> (ø)
pkg/commands/status.go 0.00% <0.00%> (ø)
pkg/commands/system.go 0.00% <0.00%> (ø)
pkg/oam/util/helper.go 73.93% <0.00%> (-3.65%) ⬇️
pkg/plugins/capcenter.go 20.33% <0.00%> (ø)
pkg/serverlib/capability.go 0.00% <0.00%> (ø)
pkg/dsl/definition/template.go 28.11% <16.45%> (+2.80%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2efeec8...868e092. Read the comment docs.

@wonderflow wonderflow marked this pull request as draft February 1, 2021 12:11
@wonderflow wonderflow force-pushed the app-status branch 2 times, most recently from dc21fd1 to f686412 Compare February 2, 2021 13:20
@wonderflow wonderflow marked this pull request as ready for review February 2, 2021 13:21
@wonderflow wonderflow force-pushed the app-status branch 2 times, most recently from a59e2a8 to e8cefa0 Compare February 2, 2021 13:25
@@ -49,6 +49,24 @@ type AppStatus struct {

// Components record the related Components created by Application Controller
Components []runtimev1alpha1.TypedReference `json:"components,omitempty"`

// Services record the status of the application services
Services []ApplicationComponentStatus `json:"services,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to "componentStatus"? I think it might also good to fold this to the "Components"

Copy link
Collaborator

@wonderflow wonderflow Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components is occupied, componentStatus not very good name

}
workloadCr, err := getObj(client, componentWorkload, name)
// workload main resource will have a unique label("app.oam.dev/resourceType"="WORKLOAD") in per component/app level
object, err := getResourceFromObj(componentWorkload, cli, ns, util.MergeMapOverrideWithDst(map[string]string{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand this. The object is not emitted to the K8s yet, how can we get the object through the client?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this stage, the resource has already ommited to K8s, just like health check

// AbstractEngine defines Definition's Render interface
type AbstractEngine interface {
Params(params interface{}) AbstractEngine
Complete(ctx process.Context, abstractTemplate string) error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally, we complete something given the "parameter" instead of the template. Am I missing something?

@wonderflow wonderflow force-pushed the app-status branch 2 times, most recently from 07c4bf2 to 14a4f3a Compare February 4, 2021 06:14
@wonderflow wonderflow merged commit b6f10bb into kubevela:master Feb 4, 2021
@wonderflow wonderflow deleted the app-status branch February 4, 2021 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] vela status app display trait status information with customized style
3 participants