service

package
v0.73.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: MPL-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package service defines Service object definitions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metadata

type Metadata struct {
	Name        string         `json:"name" validate:"required,objectName"`
	DisplayName string         `json:"displayName,omitempty" validate:"omitempty,min=0,max=63"`
	Project     string         `json:"project,omitempty" validate:"objectName"`
	Labels      v1alpha.Labels `json:"labels,omitempty" validate:"omitempty,labels"`
}

Metadata provides identity information for Service.

type Service

type Service struct {
	APIVersion string        `json:"apiVersion"`
	Kind       manifest.Kind `json:"kind"`
	Metadata   Metadata      `json:"metadata"`
	Spec       Spec          `json:"spec"`
	Status     *Status       `json:"status,omitempty"`

	Organization   string `json:"organization,omitempty"`
	ManifestSource string `json:"manifestSrc,omitempty"`
}

Service struct which mapped one to one with kind: service yaml definition

Example
package main

import (
	"context"
	"log"

	"github.com/nobl9/nobl9-go/internal/examples"
	"github.com/nobl9/nobl9-go/manifest"
	"github.com/nobl9/nobl9-go/manifest/v1alpha"
	"github.com/nobl9/nobl9-go/manifest/v1alpha/service"
)

func main() {
	// Create the object:
	myService := service.New(
		service.Metadata{
			Name:        "my-service",
			DisplayName: "My Service",
			Project:     "default",
			Labels: v1alpha.Labels{
				"team":   []string{"green", "orange"},
				"region": []string{"eu-central-1"},
			},
		},
		service.Spec{
			Description: "Example service",
		},
	)
	// Verify the object:
	if err := myService.Validate(); err != nil {
		log.Fatalf("service validation failed, err: %v", err)
	}
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.ApplyObjects(context.Background(), []manifest.Object{myService}); err != nil {
		log.Fatalf("failed to apply service, err: %v", err)
	}
}
Output:

apiVersion: n9/v1alpha
kind: Service
metadata:
  name: my-service
  displayName: My Service
  project: default
  labels:
    region:
    - eu-central-1
    team:
    - green
    - orange
spec:
  description: Example service

func New

func New(metadata Metadata, spec Spec) Service

New creates a new Service based on provided Metadata nad Spec.

func (Service) GetKind

func (s Service) GetKind() manifest.Kind

func (Service) GetManifestSource

func (s Service) GetManifestSource() string

func (Service) GetName

func (s Service) GetName() string

func (Service) GetOrganization

func (s Service) GetOrganization() string

func (Service) GetProject

func (s Service) GetProject() string

func (Service) GetVersion

func (s Service) GetVersion() string

func (Service) SetManifestSource

func (s Service) SetManifestSource(src string) manifest.Object

func (Service) SetOrganization

func (s Service) SetOrganization(org string) manifest.Object

func (Service) SetProject

func (s Service) SetProject(project string) manifest.Object

func (Service) Validate

func (s Service) Validate() error

type Spec

type Spec struct {
	Description string `json:"description" validate:"description" example:"Bleeding edge web app"`
}

Spec holds detailed information specific to Service.

type Status

type Status struct {
	SloCount int `json:"sloCount"`
}

Status holds dynamic fields returned when the Service is fetched from Nobl9 platform. Status is not part of the static object definition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL