github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv2/alb.go (about)

     1  package containerv2
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/IBM-Cloud/bluemix-go/client"
     7  )
     8  
     9  type alb struct {
    10  	client *client.Client
    11  }
    12  
    13  type AlbConfig struct {
    14  	AlbBuild             string `json:"albBuild"`
    15  	AlbID                string `json:"albID"`
    16  	AlbType              string `json:"albType"`
    17  	AuthBuild            string `json:"authBuild"`
    18  	Cluster              string `json:"cluster"`
    19  	CreatedDate          string `json:"createdDate"`
    20  	DisableDeployment    bool   `json:"disableDeployment"`
    21  	Enable               bool   `json:"enable"`
    22  	LoadBalancerHostname string `json:"loadBalancerHostname"`
    23  	Name                 string `json:"name"`
    24  	NumOfInstances       string `json:"numOfInstances"`
    25  	Resize               bool   `json:"resize"`
    26  	State                string `json:"state"`
    27  	Status               string `json:"status"`
    28  	ZoneAlb              string `json:"zone"`
    29  }
    30  
    31  // ALBClusterHealthCheckConfig configuration for ALB in-cluster health check
    32  type ALBClusterHealthCheckConfig struct {
    33  	Cluster string `json:"cluster"`
    34  	Enable  bool   `json:"enable"`
    35  }
    36  
    37  type AlbCreateResp struct {
    38  	Cluster string `json:"cluster"`
    39  	Alb     string `json:"alb"`
    40  }
    41  
    42  type AlbCreateReq struct {
    43  	Cluster         string `json:"cluster"`
    44  	EnableByDefault bool   `json:"enableByDefault"`
    45  	Type            string `json:"type"`
    46  	ZoneAlb         string `json:"zone"`
    47  	IngressImage    string `json:"ingressImage"`
    48  }
    49  
    50  type AlbImageVersions struct {
    51  	DefaultK8sVersion    string   `json:"defaultK8sVersion"`
    52  	SupportedK8sVersions []string `json:"supportedK8sVersions"`
    53  }
    54  
    55  // ALBLBConfig ingress ALB load balancer configuration
    56  type ALBLBConfig struct {
    57  	Cluster       string                    `json:"cluster" description:"The ID or name of the cluster" binding:"required"`
    58  	Type          string                    `json:"type,omitempty" description:"type of load balancers to configure ('public' or 'private')"`
    59  	ProxyProtocol *ALBLBProxyProtocolConfig `json:"proxyProtocol,omitempty" description:"PROXY protocol related configurations"`
    60  }
    61  
    62  // ALBLBProxyProtocolConfig ingress ALB load balancer Proxy Protocol configuration
    63  type ALBLBProxyProtocolConfig struct {
    64  	Enable        bool     `json:"enable" description:"PROXY protocol state"`
    65  	CIDR          []string `json:"cidr,omitempty" description:"trusted address ranges"`
    66  	HeaderTimeout int      `json:"headerTimeout,omitempty" description:"timeout value for receiving PROXY protocol headers"`
    67  }
    68  
    69  // AlbUpdateResp
    70  type AlbUpdateResp struct {
    71  	ClusterID string `json:"clusterID"`
    72  }
    73  
    74  // AutoscaleDetails
    75  type AutoscaleDetails struct {
    76  	Config *AutoscaleConfig `json:"config,omitempty" description:"Autoscaling configuration"`
    77  }
    78  
    79  // AutoscaleConfig
    80  type AutoscaleConfig struct {
    81  	MinReplicas           int    `json:"minReplicas" description:"Minimum number of replicas"`
    82  	MaxReplicas           int    `json:"maxReplicas" description:"Maximum number of replicas"`
    83  	CustomMetrics         string `json:"customMetrics,omitempty" description:"An array of MetricSpec (autoscaling.k8s.io/v2) encoded as JSON"`
    84  	CPUAverageUtilization int    `json:"cpuAverageUtilization,omitempty" description:"CPU Average Utilization"`
    85  }
    86  
    87  type ClusterALB struct {
    88  	ID                      string      `json:"id"`
    89  	Region                  string      `json:"region"`
    90  	DataCenter              string      `json:"dataCenter"`
    91  	IsPaid                  bool        `json:"isPaid"`
    92  	PublicIngressHostname   string      `json:"publicIngressHostname"`
    93  	PublicIngressSecretName string      `json:"publicIngressSecretName"`
    94  	ALBs                    []AlbConfig `json:"alb"`
    95  }
    96  
    97  // IgnoredIngressStatusErrors
    98  type IgnoredIngressStatusErrors struct {
    99  	Cluster       string   `json:"cluster" description:"the ID or name of the cluster"`
   100  	IgnoredErrors []string `json:"ignoredErrors" description:"list of error codes that the user wants to ignore"`
   101  }
   102  
   103  // IngressStatusState
   104  type IngressStatusState struct {
   105  	Cluster string `json:"cluster" description:"the ID or name of the cluster"`
   106  	Enable  bool   `json:"enable" description:"true or false to enable or disable ingress status"`
   107  }
   108  
   109  // IngressStatus struct for the top level ingress status, for a cluster
   110  type IngressStatus struct {
   111  	Cluster                string `json:"cluster"`
   112  	Enabled                bool   `json:"enabled"`
   113  	Status                 string `json:"status"`
   114  	NonTranslatedStatus    string `json:"nonTranslatedStatus"`
   115  	Message                string `json:"message"`
   116  	StatusList             []IngressComponentStatus
   117  	GeneralComponentStatus []V2IngressComponentStatus `json:"generalComponentStatus,omitempty"`
   118  	ALBStatus              []V2IngressComponentStatus `json:"albStatus,omitempty"`
   119  	RouterStatus           []V2IngressComponentStatus `json:"routerStatus,omitempty"`
   120  	SubdomainStatus        []V2IngressComponentStatus `json:"subdomainStatus,omitempty"`
   121  	SecretStatus           []V2IngressComponentStatus `json:"secretStatus,omitempty"`
   122  	IgnoredErrors          []string                   `json:"ignoredErrors" description:"list of error codes that the user wants to ignore"`
   123  }
   124  
   125  // IngressComponentStatus status of individual ingress component
   126  type IngressComponentStatus struct {
   127  	Component string `json:"component"`
   128  	Status    string `json:"status"`
   129  	Type      string `json:"type"`
   130  }
   131  
   132  // UpdateALBReq is the body of the v2 Update ALB API endpoint
   133  type UpdateALBReq struct {
   134  	ClusterID string   `json:"cluster" description:"The ID of the cluster on which the update ALB action shall be performed"`
   135  	ALBBuild  string   `json:"albBuild" description:"The version of the build to which the ALB should be updated"`
   136  	ALBList   []string `json:"albList" description:"The list of ALBs that should be updated to the requested albBuild"`
   137  }
   138  
   139  // V2IngressComponentStatus status of individual ingress component
   140  type V2IngressComponentStatus struct {
   141  	Component string   `json:"component,omitempty"`
   142  	Status    []string `json:"status,omitempty"`
   143  }
   144  
   145  // Clusters interface
   146  type Alb interface {
   147  	AddIgnoredIngressStatusErrors(ignoredErrorsReq IgnoredIngressStatusErrors, target ClusterTargetHeader) error
   148  	CreateAlb(albCreateReq AlbCreateReq, target ClusterTargetHeader) (AlbCreateResp, error)
   149  	DisableAlb(disableAlbReq AlbConfig, target ClusterTargetHeader) error
   150  	EnableAlb(enableAlbReq AlbConfig, target ClusterTargetHeader) error
   151  	GetALBAutoscaleConfiguration(clusterNameOrID, albID string, target ClusterTargetHeader) (AutoscaleDetails, error)
   152  	GetAlb(albid string, target ClusterTargetHeader) (AlbConfig, error)
   153  	GetAlbClusterHealthCheckConfig(clusterNameOrID string, target ClusterTargetHeader) (ALBClusterHealthCheckConfig, error)
   154  	GetIgnoredIngressStatusErrors(clusterNameOrID string, target ClusterTargetHeader) (IgnoredIngressStatusErrors, error)
   155  	GetIngressLoadBalancerConfig(clusterNameOrID, lbType string, target ClusterTargetHeader) (ALBLBConfig, error)
   156  	GetIngressStatus(clusterNameOrID string, target ClusterTargetHeader) (IngressStatus, error)
   157  	ListAlbImages(target ClusterTargetHeader) (AlbImageVersions, error)
   158  	ListClusterAlbs(clusterNameOrID string, target ClusterTargetHeader) ([]AlbConfig, error)
   159  	RemoveALBAutoscaleConfiguration(clusterNameOrID, albID string, target ClusterTargetHeader) error
   160  	RemoveIgnoredIngressStatusErrors(ignoredErrorsReq IgnoredIngressStatusErrors, target ClusterTargetHeader) error
   161  	SetALBAutoscaleConfiguration(clusterNameOrID, albID string, autoscaleDetails AutoscaleDetails, target ClusterTargetHeader) error
   162  	SetAlbClusterHealthCheckConfig(albHealthCheckReq ALBClusterHealthCheckConfig, target ClusterTargetHeader) error
   163  	SetIngressStatusState(ingressStatusStateReq IngressStatusState, target ClusterTargetHeader) error
   164  	UpdateAlb(updateAlbReq UpdateALBReq, target ClusterTargetHeader) error
   165  	UpdateIngressLoadBalancerConfig(lbConfig ALBLBConfig, target ClusterTargetHeader) error
   166  }
   167  
   168  func newAlbAPI(c *client.Client) Alb {
   169  	return &alb{
   170  		client: c,
   171  	}
   172  }
   173  
   174  // CreateAlb create an ALB in a specified zone and cluster
   175  func (r *alb) CreateAlb(albCreateReq AlbCreateReq, target ClusterTargetHeader) (AlbCreateResp, error) {
   176  	var successV AlbCreateResp
   177  	_, err := r.client.Post("/v2/alb/vpc/createAlb", albCreateReq, &successV, target.ToMap())
   178  	return successV, err
   179  }
   180  
   181  // DisableAlb disable an ALB in your cluster
   182  func (r *alb) DisableAlb(disableAlbReq AlbConfig, target ClusterTargetHeader) error {
   183  	// Make the request, don't care about return value
   184  	_, err := r.client.Post("/v2/alb/vpc/disableAlb", disableAlbReq, nil, target.ToMap())
   185  	return err
   186  }
   187  
   188  // EnableAlb enable an ALB in your cluster
   189  func (r *alb) EnableAlb(enableAlbReq AlbConfig, target ClusterTargetHeader) error {
   190  	// Make the request, don't care about return value
   191  	_, err := r.client.Post("/v2/alb/vpc/enableAlb", enableAlbReq, nil, target.ToMap())
   192  	return err
   193  }
   194  
   195  // GetAlb returns with the details of an ALB
   196  func (r *alb) GetAlb(albID string, target ClusterTargetHeader) (AlbConfig, error) {
   197  	var successV AlbConfig
   198  	_, err := r.client.Get(fmt.Sprintf("/v2/alb/getAlb?albID=%s", albID), &successV, target.ToMap())
   199  	return successV, err
   200  }
   201  
   202  // UpdateAlb update one or more ALBs. To update your ALB to a specified image version, automatic updates must be disabled
   203  func (r *alb) UpdateAlb(updateAlbReq UpdateALBReq, target ClusterTargetHeader) error {
   204  	// Make the request, don't care about return value
   205  	_, err := r.client.Post("/v2/alb/updateAlb", updateAlbReq, nil, target.ToMap())
   206  	return err
   207  }
   208  
   209  // ListClusterALBs returns the list of albs available for cluster
   210  func (r *alb) ListClusterAlbs(clusterNameOrID string, target ClusterTargetHeader) ([]AlbConfig, error) {
   211  	var successV ClusterALB
   212  	rawURL := fmt.Sprintf("v2/alb/getClusterAlbs?cluster=%s", clusterNameOrID)
   213  	_, err := r.client.Get(rawURL, &successV, target.ToMap())
   214  	return successV.ALBs, err
   215  }
   216  
   217  // ListAlbImages lists the default and the supported ALB image versions
   218  func (r *alb) ListAlbImages(target ClusterTargetHeader) (AlbImageVersions, error) {
   219  	var successV AlbImageVersions
   220  	_, err := r.client.Get("v2/alb/getAlbImages", &successV, target.ToMap())
   221  	return successV, err
   222  }
   223  
   224  // GetIngressStatus returns the ingress status report for the cluster
   225  func (r *alb) GetIngressStatus(clusterNameOrID string, target ClusterTargetHeader) (IngressStatus, error) {
   226  	var successV IngressStatus
   227  	_, err := r.client.Get(fmt.Sprintf("/v2/alb/getStatus?cluster=%s", clusterNameOrID), &successV, target.ToMap())
   228  	return successV, err
   229  }
   230  
   231  // GetAlbClusterHealthCheckConfig returns the ALB in-cluster healthcheck config
   232  func (r *alb) GetAlbClusterHealthCheckConfig(clusterNameOrID string, target ClusterTargetHeader) (ALBClusterHealthCheckConfig, error) {
   233  	var successV ALBClusterHealthCheckConfig
   234  	_, err := r.client.Get(fmt.Sprintf("/v2/alb/getIngressClusterHealthcheck?cluster=%s", clusterNameOrID), &successV, target.ToMap())
   235  	return successV, err
   236  }
   237  
   238  // SetAlbClusterHealthCheckConfig configure the ALB in-cluster healthcheck
   239  func (r *alb) SetAlbClusterHealthCheckConfig(albHealthCheckReq ALBClusterHealthCheckConfig, target ClusterTargetHeader) error {
   240  	// Make the request, don't care about return value
   241  	_, err := r.client.Post("/v2/alb/setIngressClusterHealthcheck", albHealthCheckReq, nil, target.ToMap())
   242  	return err
   243  }
   244  
   245  // GetIgnoredIngressStatusErrors lists of error codes that the user wants to ignore
   246  func (r *alb) GetIgnoredIngressStatusErrors(clusterNameOrID string, target ClusterTargetHeader) (IgnoredIngressStatusErrors, error) {
   247  	var successV IgnoredIngressStatusErrors
   248  	_, err := r.client.Get(fmt.Sprintf("/v2/alb/listIgnoredIngressStatusErrors?cluster=%s", clusterNameOrID), &successV, target.ToMap())
   249  	return successV, err
   250  }
   251  
   252  // AddIgnoredIngressStatusErrors ignore one or more ingress status error
   253  func (r *alb) AddIgnoredIngressStatusErrors(ignoredErrorsReq IgnoredIngressStatusErrors, target ClusterTargetHeader) error {
   254  	// Make the request, don't care about return value
   255  	_, err := r.client.Post("/v2/alb/addIgnoredIngressStatusErrors", ignoredErrorsReq, nil, target.ToMap())
   256  	return err
   257  }
   258  
   259  // RemoveIgnoredIngressStatusErrors remove one or more ignored ingress status error
   260  func (r *alb) RemoveIgnoredIngressStatusErrors(ignoredErrorsReq IgnoredIngressStatusErrors, target ClusterTargetHeader) error {
   261  	// Make the request, don't care about return value
   262  	_, err := r.client.DeleteWithBody("/v2/alb/removeIgnoredIngressStatusErrors", ignoredErrorsReq, nil, target.ToMap())
   263  	return err
   264  }
   265  
   266  // SetIngressStatusState set the state of the ingress status for a cluster
   267  func (r *alb) SetIngressStatusState(ingressStatusStateReq IngressStatusState, target ClusterTargetHeader) error {
   268  	// Make the request, don't care about return value
   269  	_, err := r.client.Post("/v2/alb/setIngressStatusState", ingressStatusStateReq, nil, target.ToMap())
   270  	return err
   271  }
   272  
   273  // GetIngressLoadBalancerConfig get the configuration of load balancers for Ingress ALBs
   274  func (r *alb) GetIngressLoadBalancerConfig(clusterNameOrID, lbType string, target ClusterTargetHeader) (ALBLBConfig, error) {
   275  	var successV ALBLBConfig
   276  	_, err := r.client.Get(fmt.Sprintf("/ingress/v2/load-balancer/configuration?cluster=%s&type=%s", clusterNameOrID, lbType), &successV, target.ToMap())
   277  	return successV, err
   278  }
   279  
   280  // UpdateIngressLoadBalancerConfig update the configuration of load balancers for Ingress ALBs
   281  func (r *alb) UpdateIngressLoadBalancerConfig(lbConfig ALBLBConfig, target ClusterTargetHeader) error {
   282  	// Make the request, don't care about return value
   283  	_, err := r.client.Patch("/ingress/v2/load-balancer/configuration", lbConfig, nil, target.ToMap())
   284  	return err
   285  }
   286  
   287  // GetALBAutoscaleConfiguration get the autoscaling configuration for an ALB
   288  func (r *alb) GetALBAutoscaleConfiguration(clusterNameOrID, albID string, target ClusterTargetHeader) (AutoscaleDetails, error) {
   289  	var successV AutoscaleDetails
   290  	_, err := r.client.Get(fmt.Sprintf("/ingress/v2/clusters/%s/albs/%s/autoscale", clusterNameOrID, albID), &successV, target.ToMap())
   291  	return successV, err
   292  }
   293  
   294  // SetALBAutoscaleConfiguration set the autoscaling configuration for an ALB
   295  func (r *alb) SetALBAutoscaleConfiguration(clusterNameOrID, albID string, autoscaleDetails AutoscaleDetails, target ClusterTargetHeader) error {
   296  	// Make the request, don't care about return value
   297  	_, err := r.client.Put(fmt.Sprintf("/ingress/v2/clusters/%s/albs/%s/autoscale", clusterNameOrID, albID), autoscaleDetails, nil, target.ToMap())
   298  	return err
   299  }
   300  
   301  // RemoveALBAutoscaleConfiguration delete the autoscaling configuration for an ALB
   302  func (r *alb) RemoveALBAutoscaleConfiguration(clusterNameOrID, albID string, target ClusterTargetHeader) error {
   303  	// Make the request, don't care about return value
   304  	_, err := r.client.Delete(fmt.Sprintf("/ingress/v2/clusters/%s/albs/%s/autoscale", clusterNameOrID, albID), nil, nil, target.ToMap())
   305  	return err
   306  }