deployment_target.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models
  2. import (
  3. "github.com/google/uuid"
  4. "github.com/porter-dev/porter/api/types"
  5. "gorm.io/gorm"
  6. )
  7. // DeploymentTargetSelectorType is the type of selector for a deployment target
  8. type DeploymentTargetSelectorType string
  9. const (
  10. // DeploymentTargetSelectorType_Namespace indicates that the selector is a namespace
  11. DeploymentTargetSelectorType_Namespace DeploymentTargetSelectorType = "NAMESPACE"
  12. )
  13. // DeploymentTarget represents a deployment target on a given cluster
  14. type DeploymentTarget struct {
  15. gorm.Model
  16. // ID is a UUID for the Revision
  17. ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
  18. // ClusterID is the ID of the cluster that is being targeted.
  19. ClusterID int `json:"cluster_id"`
  20. // ProjectID is the ID of the project that the target belongs to.
  21. ProjectID int `json:"project_id"`
  22. // VanityName is a human-readable name for the deployment target. It will be unique within a project once all existing deployment targets have been backfilled (tracking: POR-1991)
  23. VanityName string `json:"vanity_name" gorm:"default:''"`
  24. // Selector is the identifier to target.
  25. Selector string `json:"selector"`
  26. // SelectorType is the kind of selector (i.e. NAMESPACE or LABEL).
  27. SelectorType DeploymentTargetSelectorType `json:"selector_type"`
  28. // Preview is a boolean indicating whether this target is a preview target.
  29. Preview bool `gorm:"default:false" json:"preview"`
  30. // Metadata is a JSONB column that stores arbitrary metadata about the deployment target
  31. Metadata JSONB `json:"metadata" sql:"type:jsonb" gorm:"type:jsonb;default:'{}'"`
  32. // IsDefault indicates whether this is the default deployment target for the cluster
  33. IsDefault bool `gorm:"default:false" json:"is_default"`
  34. }
  35. // ToDeploymentTargetType generates an external types.PorterApp to be shared over REST
  36. func (d *DeploymentTarget) ToDeploymentTargetType() *types.DeploymentTarget {
  37. return &types.DeploymentTarget{
  38. ID: d.ID,
  39. ProjectID: uint(d.ProjectID),
  40. ClusterID: uint(d.ClusterID),
  41. Namespace: d.Selector,
  42. IsPreview: d.Preview,
  43. IsDefault: d.IsDefault,
  44. Name: d.VanityName,
  45. CreatedAtUTC: d.CreatedAt,
  46. UpdatedAtUTC: d.UpdatedAt,
  47. }
  48. }