github.com/pulumi/pulumi-kubernetes/sdk/v3@v3.30.2/go/kubernetes/core/v1/service.go (about)

     1  // Code generated by pulumigen DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package v1
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
    11  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    12  )
    13  
    14  // Service is a named abstraction of software service (for example, mysql) consisting of local port (for example 3306) that the proxy listens on, and the selector that determines which pods will answer requests sent through the proxy.
    15  //
    16  // This resource waits until its status is ready before registering success
    17  // for create/update, and populating output properties from the current state of the resource.
    18  // The following conditions are used to determine whether the resource creation has
    19  // succeeded or failed:
    20  //
    21  //  1. Service object exists.
    22  //  2. Related Endpoint objects are created. Each time we get an update, wait 10 seconds
    23  //     for any stragglers.
    24  //  3. The endpoints objects target some number of living objects (unless the Service is
    25  //     an "empty headless" Service [1] or a Service with '.spec.type: ExternalName').
    26  //  4. External IP address is allocated (if Service has '.spec.type: LoadBalancer').
    27  //
    28  // Known limitations:
    29  // Services targeting ReplicaSets (and, by extension, Deployments,
    30  // StatefulSets, etc.) with '.spec.replicas' set to 0 are not handled, and will time
    31  // out. To work around this limitation, set 'pulumi.com/skipAwait: "true"' on
    32  // '.metadata.annotations' for the Service. Work to handle this case is in progress [2].
    33  //
    34  // [1] https://kubernetes.io/docs/concepts/services-networking/service/#headless-services
    35  // [2] https://github.com/pulumi/pulumi-kubernetes/pull/703
    36  //
    37  // If the Service has not reached a Ready state after 10 minutes, it will
    38  // time out and mark the resource update as Failed. You can override the default timeout value
    39  // by setting the 'customTimeouts' option on the resource.
    40  //
    41  // ## Example Usage
    42  // ### Create a Service with auto-naming
    43  // ```go
    44  // package main
    45  //
    46  // import (
    47  //
    48  //	corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
    49  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    50  //
    51  // )
    52  //
    53  //	func main() {
    54  //		pulumi.Run(func(ctx *pulumi.Context) error {
    55  //			_, err := corev1.NewService(ctx, "service", &corev1.ServiceArgs{
    56  //				Spec: &corev1.ServiceSpecArgs{
    57  //					Ports: corev1.ServicePortArray{
    58  //						&corev1.ServicePortArgs{
    59  //							Port:       pulumi.Int(80),
    60  //							Protocol:   pulumi.String("TCP"),
    61  //							TargetPort: pulumi.Any(9376),
    62  //						},
    63  //					},
    64  //					Selector: pulumi.StringMap{
    65  //						"app": pulumi.String("MyApp"),
    66  //					},
    67  //				},
    68  //			})
    69  //			if err != nil {
    70  //				return err
    71  //			}
    72  //			return nil
    73  //		})
    74  //	}
    75  //
    76  // ```
    77  // ### Create a Service with a user-specified name
    78  // ```go
    79  // package main
    80  //
    81  // import (
    82  //
    83  //	corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
    84  //	metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
    85  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    86  //
    87  // )
    88  //
    89  //	func main() {
    90  //		pulumi.Run(func(ctx *pulumi.Context) error {
    91  //			_, err := corev1.NewService(ctx, "service", &corev1.ServiceArgs{
    92  //				Metadata: &metav1.ObjectMetaArgs{
    93  //					Name: pulumi.String("my-service"),
    94  //				},
    95  //				Spec: &corev1.ServiceSpecArgs{
    96  //					Ports: corev1.ServicePortArray{
    97  //						&corev1.ServicePortArgs{
    98  //							Port:       pulumi.Int(80),
    99  //							Protocol:   pulumi.String("TCP"),
   100  //							TargetPort: pulumi.Any(9376),
   101  //						},
   102  //					},
   103  //					Selector: pulumi.StringMap{
   104  //						"app": pulumi.String("MyApp"),
   105  //					},
   106  //				},
   107  //			})
   108  //			if err != nil {
   109  //				return err
   110  //			}
   111  //			return nil
   112  //		})
   113  //	}
   114  //
   115  // ```
   116  type Service struct {
   117  	pulumi.CustomResourceState
   118  
   119  	// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
   120  	ApiVersion pulumi.StringPtrOutput `pulumi:"apiVersion"`
   121  	// Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
   122  	Kind pulumi.StringPtrOutput `pulumi:"kind"`
   123  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   124  	Metadata metav1.ObjectMetaPtrOutput `pulumi:"metadata"`
   125  	// Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   126  	Spec ServiceSpecPtrOutput `pulumi:"spec"`
   127  	// Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   128  	Status ServiceStatusPtrOutput `pulumi:"status"`
   129  }
   130  
   131  // NewService registers a new resource with the given unique name, arguments, and options.
   132  func NewService(ctx *pulumi.Context,
   133  	name string, args *ServiceArgs, opts ...pulumi.ResourceOption) (*Service, error) {
   134  	if args == nil {
   135  		args = &ServiceArgs{}
   136  	}
   137  
   138  	args.ApiVersion = pulumi.StringPtr("v1")
   139  	args.Kind = pulumi.StringPtr("Service")
   140  	var resource Service
   141  	err := ctx.RegisterResource("kubernetes:core/v1:Service", name, args, &resource, opts...)
   142  	if err != nil {
   143  		return nil, err
   144  	}
   145  	return &resource, nil
   146  }
   147  
   148  // GetService gets an existing Service resource's state with the given name, ID, and optional
   149  // state properties that are used to uniquely qualify the lookup (nil if not required).
   150  func GetService(ctx *pulumi.Context,
   151  	name string, id pulumi.IDInput, state *ServiceState, opts ...pulumi.ResourceOption) (*Service, error) {
   152  	var resource Service
   153  	err := ctx.ReadResource("kubernetes:core/v1:Service", name, id, state, &resource, opts...)
   154  	if err != nil {
   155  		return nil, err
   156  	}
   157  	return &resource, nil
   158  }
   159  
   160  // Input properties used for looking up and filtering Service resources.
   161  type serviceState struct {
   162  }
   163  
   164  type ServiceState struct {
   165  }
   166  
   167  func (ServiceState) ElementType() reflect.Type {
   168  	return reflect.TypeOf((*serviceState)(nil)).Elem()
   169  }
   170  
   171  type serviceArgs struct {
   172  	// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
   173  	ApiVersion *string `pulumi:"apiVersion"`
   174  	// Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
   175  	Kind *string `pulumi:"kind"`
   176  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   177  	Metadata *metav1.ObjectMeta `pulumi:"metadata"`
   178  	// Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   179  	Spec *ServiceSpec `pulumi:"spec"`
   180  }
   181  
   182  // The set of arguments for constructing a Service resource.
   183  type ServiceArgs struct {
   184  	// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
   185  	ApiVersion pulumi.StringPtrInput
   186  	// Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
   187  	Kind pulumi.StringPtrInput
   188  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   189  	Metadata metav1.ObjectMetaPtrInput
   190  	// Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   191  	Spec ServiceSpecPtrInput
   192  }
   193  
   194  func (ServiceArgs) ElementType() reflect.Type {
   195  	return reflect.TypeOf((*serviceArgs)(nil)).Elem()
   196  }
   197  
   198  type ServiceInput interface {
   199  	pulumi.Input
   200  
   201  	ToServiceOutput() ServiceOutput
   202  	ToServiceOutputWithContext(ctx context.Context) ServiceOutput
   203  }
   204  
   205  func (*Service) ElementType() reflect.Type {
   206  	return reflect.TypeOf((**Service)(nil)).Elem()
   207  }
   208  
   209  func (i *Service) ToServiceOutput() ServiceOutput {
   210  	return i.ToServiceOutputWithContext(context.Background())
   211  }
   212  
   213  func (i *Service) ToServiceOutputWithContext(ctx context.Context) ServiceOutput {
   214  	return pulumi.ToOutputWithContext(ctx, i).(ServiceOutput)
   215  }
   216  
   217  // ServiceArrayInput is an input type that accepts ServiceArray and ServiceArrayOutput values.
   218  // You can construct a concrete instance of `ServiceArrayInput` via:
   219  //
   220  //	ServiceArray{ ServiceArgs{...} }
   221  type ServiceArrayInput interface {
   222  	pulumi.Input
   223  
   224  	ToServiceArrayOutput() ServiceArrayOutput
   225  	ToServiceArrayOutputWithContext(context.Context) ServiceArrayOutput
   226  }
   227  
   228  type ServiceArray []ServiceInput
   229  
   230  func (ServiceArray) ElementType() reflect.Type {
   231  	return reflect.TypeOf((*[]*Service)(nil)).Elem()
   232  }
   233  
   234  func (i ServiceArray) ToServiceArrayOutput() ServiceArrayOutput {
   235  	return i.ToServiceArrayOutputWithContext(context.Background())
   236  }
   237  
   238  func (i ServiceArray) ToServiceArrayOutputWithContext(ctx context.Context) ServiceArrayOutput {
   239  	return pulumi.ToOutputWithContext(ctx, i).(ServiceArrayOutput)
   240  }
   241  
   242  // ServiceMapInput is an input type that accepts ServiceMap and ServiceMapOutput values.
   243  // You can construct a concrete instance of `ServiceMapInput` via:
   244  //
   245  //	ServiceMap{ "key": ServiceArgs{...} }
   246  type ServiceMapInput interface {
   247  	pulumi.Input
   248  
   249  	ToServiceMapOutput() ServiceMapOutput
   250  	ToServiceMapOutputWithContext(context.Context) ServiceMapOutput
   251  }
   252  
   253  type ServiceMap map[string]ServiceInput
   254  
   255  func (ServiceMap) ElementType() reflect.Type {
   256  	return reflect.TypeOf((*map[string]*Service)(nil)).Elem()
   257  }
   258  
   259  func (i ServiceMap) ToServiceMapOutput() ServiceMapOutput {
   260  	return i.ToServiceMapOutputWithContext(context.Background())
   261  }
   262  
   263  func (i ServiceMap) ToServiceMapOutputWithContext(ctx context.Context) ServiceMapOutput {
   264  	return pulumi.ToOutputWithContext(ctx, i).(ServiceMapOutput)
   265  }
   266  
   267  type ServiceOutput struct{ *pulumi.OutputState }
   268  
   269  func (ServiceOutput) ElementType() reflect.Type {
   270  	return reflect.TypeOf((**Service)(nil)).Elem()
   271  }
   272  
   273  func (o ServiceOutput) ToServiceOutput() ServiceOutput {
   274  	return o
   275  }
   276  
   277  func (o ServiceOutput) ToServiceOutputWithContext(ctx context.Context) ServiceOutput {
   278  	return o
   279  }
   280  
   281  // APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
   282  func (o ServiceOutput) ApiVersion() pulumi.StringPtrOutput {
   283  	return o.ApplyT(func(v *Service) pulumi.StringPtrOutput { return v.ApiVersion }).(pulumi.StringPtrOutput)
   284  }
   285  
   286  // Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
   287  func (o ServiceOutput) Kind() pulumi.StringPtrOutput {
   288  	return o.ApplyT(func(v *Service) pulumi.StringPtrOutput { return v.Kind }).(pulumi.StringPtrOutput)
   289  }
   290  
   291  // Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   292  func (o ServiceOutput) Metadata() metav1.ObjectMetaPtrOutput {
   293  	return o.ApplyT(func(v *Service) metav1.ObjectMetaPtrOutput { return v.Metadata }).(metav1.ObjectMetaPtrOutput)
   294  }
   295  
   296  // Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   297  func (o ServiceOutput) Spec() ServiceSpecPtrOutput {
   298  	return o.ApplyT(func(v *Service) ServiceSpecPtrOutput { return v.Spec }).(ServiceSpecPtrOutput)
   299  }
   300  
   301  // Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   302  func (o ServiceOutput) Status() ServiceStatusPtrOutput {
   303  	return o.ApplyT(func(v *Service) ServiceStatusPtrOutput { return v.Status }).(ServiceStatusPtrOutput)
   304  }
   305  
   306  type ServiceArrayOutput struct{ *pulumi.OutputState }
   307  
   308  func (ServiceArrayOutput) ElementType() reflect.Type {
   309  	return reflect.TypeOf((*[]*Service)(nil)).Elem()
   310  }
   311  
   312  func (o ServiceArrayOutput) ToServiceArrayOutput() ServiceArrayOutput {
   313  	return o
   314  }
   315  
   316  func (o ServiceArrayOutput) ToServiceArrayOutputWithContext(ctx context.Context) ServiceArrayOutput {
   317  	return o
   318  }
   319  
   320  func (o ServiceArrayOutput) Index(i pulumi.IntInput) ServiceOutput {
   321  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Service {
   322  		return vs[0].([]*Service)[vs[1].(int)]
   323  	}).(ServiceOutput)
   324  }
   325  
   326  type ServiceMapOutput struct{ *pulumi.OutputState }
   327  
   328  func (ServiceMapOutput) ElementType() reflect.Type {
   329  	return reflect.TypeOf((*map[string]*Service)(nil)).Elem()
   330  }
   331  
   332  func (o ServiceMapOutput) ToServiceMapOutput() ServiceMapOutput {
   333  	return o
   334  }
   335  
   336  func (o ServiceMapOutput) ToServiceMapOutputWithContext(ctx context.Context) ServiceMapOutput {
   337  	return o
   338  }
   339  
   340  func (o ServiceMapOutput) MapIndex(k pulumi.StringInput) ServiceOutput {
   341  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Service {
   342  		return vs[0].(map[string]*Service)[vs[1].(string)]
   343  	}).(ServiceOutput)
   344  }
   345  
   346  func init() {
   347  	pulumi.RegisterInputType(reflect.TypeOf((*ServiceInput)(nil)).Elem(), &Service{})
   348  	pulumi.RegisterInputType(reflect.TypeOf((*ServiceArrayInput)(nil)).Elem(), ServiceArray{})
   349  	pulumi.RegisterInputType(reflect.TypeOf((*ServiceMapInput)(nil)).Elem(), ServiceMap{})
   350  	pulumi.RegisterOutputType(ServiceOutput{})
   351  	pulumi.RegisterOutputType(ServiceArrayOutput{})
   352  	pulumi.RegisterOutputType(ServiceMapOutput{})
   353  }