github.com/pulumi/pulumi-kubernetes/sdk/v3@v3.30.2/go/kubernetes/apps/v1/statefulSet.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  // StatefulSet represents a set of pods with consistent identities. Identities are defined as:
    15  //   - Network: A single stable DNS and hostname.
    16  //   - Storage: As many VolumeClaims as requested.
    17  //
    18  // The StatefulSet guarantees that a given network identity will always map to the same storage identity.
    19  //
    20  // This resource waits until its status is ready before registering success
    21  // for create/update, and populating output properties from the current state of the resource.
    22  // The following conditions are used to determine whether the resource creation has
    23  // succeeded or failed:
    24  //
    25  //  1. The value of 'spec.replicas' matches '.status.replicas', '.status.currentReplicas',
    26  //     and '.status.readyReplicas'.
    27  //  2. The value of '.status.updateRevision' matches '.status.currentRevision'.
    28  //
    29  // If the StatefulSet has not reached a Ready state after 10 minutes, it will
    30  // time out and mark the resource update as Failed. You can override the default timeout value
    31  // by setting the 'customTimeouts' option on the resource.
    32  //
    33  // ## Example Usage
    34  // ### Create a StatefulSet with auto-naming
    35  // ```go
    36  // package main
    37  //
    38  // import (
    39  //
    40  //	appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/apps/v1"
    41  //	corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
    42  //	metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
    43  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    44  //
    45  // )
    46  //
    47  //	func main() {
    48  //		pulumi.Run(func(ctx *pulumi.Context) error {
    49  //			service, err := corev1.NewService(ctx, "service", &corev1.ServiceArgs{
    50  //				Metadata: &metav1.ObjectMetaArgs{
    51  //					Labels: pulumi.StringMap{
    52  //						"app": pulumi.String("nginx"),
    53  //					},
    54  //				},
    55  //				Spec: &corev1.ServiceSpecArgs{
    56  //					ClusterIP: pulumi.String("None"),
    57  //					Ports: corev1.ServicePortArray{
    58  //						&corev1.ServicePortArgs{
    59  //							Name: pulumi.String("web"),
    60  //							Port: pulumi.Int(80),
    61  //						},
    62  //					},
    63  //					Selector: pulumi.StringMap{
    64  //						"app": pulumi.String("nginx"),
    65  //					},
    66  //				},
    67  //			})
    68  //			if err != nil {
    69  //				return err
    70  //			}
    71  //			_, err = appsv1.NewStatefulSet(ctx, "statefulset", &appsv1.StatefulSetArgs{
    72  //				Spec: &appsv1.StatefulSetSpecArgs{
    73  //					Replicas: pulumi.Int(3),
    74  //					Selector: &metav1.LabelSelectorArgs{
    75  //						MatchLabels: pulumi.StringMap{
    76  //							"app": pulumi.String("nginx"),
    77  //						},
    78  //					},
    79  //					ServiceName: service.Metadata.ApplyT(func(metadata metav1.ObjectMeta) (*string, error) {
    80  //						return &metadata.Name, nil
    81  //					}).(pulumi.StringPtrOutput),
    82  //					Template: &corev1.PodTemplateSpecArgs{
    83  //						Metadata: &metav1.ObjectMetaArgs{
    84  //							Labels: pulumi.StringMap{
    85  //								"app": pulumi.String("nginx"),
    86  //							},
    87  //						},
    88  //						Spec: &corev1.PodSpecArgs{
    89  //							Containers: corev1.ContainerArray{
    90  //								&corev1.ContainerArgs{
    91  //									Image: pulumi.String("nginx:stable-alpine3.17-slim"),
    92  //									Name:  pulumi.String("nginx"),
    93  //									Ports: corev1.ContainerPortArray{
    94  //										&corev1.ContainerPortArgs{
    95  //											ContainerPort: pulumi.Int(80),
    96  //											Name:          pulumi.String("web"),
    97  //										},
    98  //									},
    99  //									VolumeMounts: corev1.VolumeMountArray{
   100  //										&corev1.VolumeMountArgs{
   101  //											MountPath: pulumi.String("/usr/share/nginx/html"),
   102  //											Name:      pulumi.String("www"),
   103  //										},
   104  //									},
   105  //								},
   106  //							},
   107  //							TerminationGracePeriodSeconds: pulumi.Int(10),
   108  //						},
   109  //					},
   110  //					VolumeClaimTemplates: []corev1.PersistentVolumeClaimTypeArgs{
   111  //						{
   112  //							Metadata: {
   113  //								Name: pulumi.String("www"),
   114  //							},
   115  //							Spec: {
   116  //								AccessModes: pulumi.StringArray{
   117  //									pulumi.String("ReadWriteOnce"),
   118  //								},
   119  //								Resources: {
   120  //									Requests: {
   121  //										"storage": pulumi.String("1Gi"),
   122  //									},
   123  //								},
   124  //							},
   125  //						},
   126  //					},
   127  //				},
   128  //			})
   129  //			if err != nil {
   130  //				return err
   131  //			}
   132  //			return nil
   133  //		})
   134  //	}
   135  //
   136  // ```
   137  // ### Create a StatefulSet with a user-specified name
   138  // ```go
   139  // package main
   140  //
   141  // import (
   142  //
   143  //	appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/apps/v1"
   144  //	corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
   145  //	metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
   146  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
   147  //
   148  // )
   149  //
   150  //	func main() {
   151  //		pulumi.Run(func(ctx *pulumi.Context) error {
   152  //			service, err := corev1.NewService(ctx, "service", &corev1.ServiceArgs{
   153  //				Metadata: &metav1.ObjectMetaArgs{
   154  //					Labels: pulumi.StringMap{
   155  //						"app": pulumi.String("nginx"),
   156  //					},
   157  //					Name: pulumi.String("nginx"),
   158  //				},
   159  //				Spec: &corev1.ServiceSpecArgs{
   160  //					ClusterIP: pulumi.String("None"),
   161  //					Ports: corev1.ServicePortArray{
   162  //						&corev1.ServicePortArgs{
   163  //							Name: pulumi.String("web"),
   164  //							Port: pulumi.Int(80),
   165  //						},
   166  //					},
   167  //					Selector: pulumi.StringMap{
   168  //						"app": pulumi.String("nginx"),
   169  //					},
   170  //				},
   171  //			})
   172  //			if err != nil {
   173  //				return err
   174  //			}
   175  //			_, err = appsv1.NewStatefulSet(ctx, "statefulset", &appsv1.StatefulSetArgs{
   176  //				Metadata: &metav1.ObjectMetaArgs{
   177  //					Name: pulumi.String("web"),
   178  //				},
   179  //				Spec: &appsv1.StatefulSetSpecArgs{
   180  //					Replicas: pulumi.Int(3),
   181  //					Selector: &metav1.LabelSelectorArgs{
   182  //						MatchLabels: pulumi.StringMap{
   183  //							"app": pulumi.String("nginx"),
   184  //						},
   185  //					},
   186  //					ServiceName: service.Metadata.ApplyT(func(metadata metav1.ObjectMeta) (*string, error) {
   187  //						return &metadata.Name, nil
   188  //					}).(pulumi.StringPtrOutput),
   189  //					Template: &corev1.PodTemplateSpecArgs{
   190  //						Metadata: &metav1.ObjectMetaArgs{
   191  //							Labels: pulumi.StringMap{
   192  //								"app": pulumi.String("nginx"),
   193  //							},
   194  //						},
   195  //						Spec: &corev1.PodSpecArgs{
   196  //							Containers: corev1.ContainerArray{
   197  //								&corev1.ContainerArgs{
   198  //									Image: pulumi.String("nginx:stable-alpine3.17-slim"),
   199  //									Name:  pulumi.String("nginx"),
   200  //									Ports: corev1.ContainerPortArray{
   201  //										&corev1.ContainerPortArgs{
   202  //											ContainerPort: pulumi.Int(80),
   203  //											Name:          pulumi.String("web"),
   204  //										},
   205  //									},
   206  //									VolumeMounts: corev1.VolumeMountArray{
   207  //										&corev1.VolumeMountArgs{
   208  //											MountPath: pulumi.String("/usr/share/nginx/html"),
   209  //											Name:      pulumi.String("www"),
   210  //										},
   211  //									},
   212  //								},
   213  //							},
   214  //							TerminationGracePeriodSeconds: pulumi.Int(10),
   215  //						},
   216  //					},
   217  //					VolumeClaimTemplates: []corev1.PersistentVolumeClaimTypeArgs{
   218  //						{
   219  //							Metadata: {
   220  //								Name: pulumi.String("www"),
   221  //							},
   222  //							Spec: {
   223  //								AccessModes: pulumi.StringArray{
   224  //									pulumi.String("ReadWriteOnce"),
   225  //								},
   226  //								Resources: {
   227  //									Requests: {
   228  //										"storage": pulumi.String("1Gi"),
   229  //									},
   230  //								},
   231  //							},
   232  //						},
   233  //					},
   234  //				},
   235  //			})
   236  //			if err != nil {
   237  //				return err
   238  //			}
   239  //			return nil
   240  //		})
   241  //	}
   242  //
   243  // ```
   244  type StatefulSet struct {
   245  	pulumi.CustomResourceState
   246  
   247  	// 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
   248  	ApiVersion pulumi.StringPtrOutput `pulumi:"apiVersion"`
   249  	// 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
   250  	Kind pulumi.StringPtrOutput `pulumi:"kind"`
   251  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   252  	Metadata metav1.ObjectMetaPtrOutput `pulumi:"metadata"`
   253  	// Spec defines the desired identities of pods in this set.
   254  	Spec StatefulSetSpecPtrOutput `pulumi:"spec"`
   255  	// Status is the current status of Pods in this StatefulSet. This data may be out of date by some window of time.
   256  	Status StatefulSetStatusPtrOutput `pulumi:"status"`
   257  }
   258  
   259  // NewStatefulSet registers a new resource with the given unique name, arguments, and options.
   260  func NewStatefulSet(ctx *pulumi.Context,
   261  	name string, args *StatefulSetArgs, opts ...pulumi.ResourceOption) (*StatefulSet, error) {
   262  	if args == nil {
   263  		args = &StatefulSetArgs{}
   264  	}
   265  
   266  	args.ApiVersion = pulumi.StringPtr("apps/v1")
   267  	args.Kind = pulumi.StringPtr("StatefulSet")
   268  	aliases := pulumi.Aliases([]pulumi.Alias{
   269  		{
   270  			Type: pulumi.String("kubernetes:apps/v1beta1:StatefulSet"),
   271  		},
   272  		{
   273  			Type: pulumi.String("kubernetes:apps/v1beta2:StatefulSet"),
   274  		},
   275  	})
   276  	opts = append(opts, aliases)
   277  	var resource StatefulSet
   278  	err := ctx.RegisterResource("kubernetes:apps/v1:StatefulSet", name, args, &resource, opts...)
   279  	if err != nil {
   280  		return nil, err
   281  	}
   282  	return &resource, nil
   283  }
   284  
   285  // GetStatefulSet gets an existing StatefulSet resource's state with the given name, ID, and optional
   286  // state properties that are used to uniquely qualify the lookup (nil if not required).
   287  func GetStatefulSet(ctx *pulumi.Context,
   288  	name string, id pulumi.IDInput, state *StatefulSetState, opts ...pulumi.ResourceOption) (*StatefulSet, error) {
   289  	var resource StatefulSet
   290  	err := ctx.ReadResource("kubernetes:apps/v1:StatefulSet", name, id, state, &resource, opts...)
   291  	if err != nil {
   292  		return nil, err
   293  	}
   294  	return &resource, nil
   295  }
   296  
   297  // Input properties used for looking up and filtering StatefulSet resources.
   298  type statefulSetState struct {
   299  }
   300  
   301  type StatefulSetState struct {
   302  }
   303  
   304  func (StatefulSetState) ElementType() reflect.Type {
   305  	return reflect.TypeOf((*statefulSetState)(nil)).Elem()
   306  }
   307  
   308  type statefulSetArgs struct {
   309  	// 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
   310  	ApiVersion *string `pulumi:"apiVersion"`
   311  	// 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
   312  	Kind *string `pulumi:"kind"`
   313  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   314  	Metadata *metav1.ObjectMeta `pulumi:"metadata"`
   315  	// Spec defines the desired identities of pods in this set.
   316  	Spec *StatefulSetSpec `pulumi:"spec"`
   317  }
   318  
   319  // The set of arguments for constructing a StatefulSet resource.
   320  type StatefulSetArgs struct {
   321  	// 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
   322  	ApiVersion pulumi.StringPtrInput
   323  	// 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
   324  	Kind pulumi.StringPtrInput
   325  	// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   326  	Metadata metav1.ObjectMetaPtrInput
   327  	// Spec defines the desired identities of pods in this set.
   328  	Spec StatefulSetSpecPtrInput
   329  }
   330  
   331  func (StatefulSetArgs) ElementType() reflect.Type {
   332  	return reflect.TypeOf((*statefulSetArgs)(nil)).Elem()
   333  }
   334  
   335  type StatefulSetInput interface {
   336  	pulumi.Input
   337  
   338  	ToStatefulSetOutput() StatefulSetOutput
   339  	ToStatefulSetOutputWithContext(ctx context.Context) StatefulSetOutput
   340  }
   341  
   342  func (*StatefulSet) ElementType() reflect.Type {
   343  	return reflect.TypeOf((**StatefulSet)(nil)).Elem()
   344  }
   345  
   346  func (i *StatefulSet) ToStatefulSetOutput() StatefulSetOutput {
   347  	return i.ToStatefulSetOutputWithContext(context.Background())
   348  }
   349  
   350  func (i *StatefulSet) ToStatefulSetOutputWithContext(ctx context.Context) StatefulSetOutput {
   351  	return pulumi.ToOutputWithContext(ctx, i).(StatefulSetOutput)
   352  }
   353  
   354  // StatefulSetArrayInput is an input type that accepts StatefulSetArray and StatefulSetArrayOutput values.
   355  // You can construct a concrete instance of `StatefulSetArrayInput` via:
   356  //
   357  //	StatefulSetArray{ StatefulSetArgs{...} }
   358  type StatefulSetArrayInput interface {
   359  	pulumi.Input
   360  
   361  	ToStatefulSetArrayOutput() StatefulSetArrayOutput
   362  	ToStatefulSetArrayOutputWithContext(context.Context) StatefulSetArrayOutput
   363  }
   364  
   365  type StatefulSetArray []StatefulSetInput
   366  
   367  func (StatefulSetArray) ElementType() reflect.Type {
   368  	return reflect.TypeOf((*[]*StatefulSet)(nil)).Elem()
   369  }
   370  
   371  func (i StatefulSetArray) ToStatefulSetArrayOutput() StatefulSetArrayOutput {
   372  	return i.ToStatefulSetArrayOutputWithContext(context.Background())
   373  }
   374  
   375  func (i StatefulSetArray) ToStatefulSetArrayOutputWithContext(ctx context.Context) StatefulSetArrayOutput {
   376  	return pulumi.ToOutputWithContext(ctx, i).(StatefulSetArrayOutput)
   377  }
   378  
   379  // StatefulSetMapInput is an input type that accepts StatefulSetMap and StatefulSetMapOutput values.
   380  // You can construct a concrete instance of `StatefulSetMapInput` via:
   381  //
   382  //	StatefulSetMap{ "key": StatefulSetArgs{...} }
   383  type StatefulSetMapInput interface {
   384  	pulumi.Input
   385  
   386  	ToStatefulSetMapOutput() StatefulSetMapOutput
   387  	ToStatefulSetMapOutputWithContext(context.Context) StatefulSetMapOutput
   388  }
   389  
   390  type StatefulSetMap map[string]StatefulSetInput
   391  
   392  func (StatefulSetMap) ElementType() reflect.Type {
   393  	return reflect.TypeOf((*map[string]*StatefulSet)(nil)).Elem()
   394  }
   395  
   396  func (i StatefulSetMap) ToStatefulSetMapOutput() StatefulSetMapOutput {
   397  	return i.ToStatefulSetMapOutputWithContext(context.Background())
   398  }
   399  
   400  func (i StatefulSetMap) ToStatefulSetMapOutputWithContext(ctx context.Context) StatefulSetMapOutput {
   401  	return pulumi.ToOutputWithContext(ctx, i).(StatefulSetMapOutput)
   402  }
   403  
   404  type StatefulSetOutput struct{ *pulumi.OutputState }
   405  
   406  func (StatefulSetOutput) ElementType() reflect.Type {
   407  	return reflect.TypeOf((**StatefulSet)(nil)).Elem()
   408  }
   409  
   410  func (o StatefulSetOutput) ToStatefulSetOutput() StatefulSetOutput {
   411  	return o
   412  }
   413  
   414  func (o StatefulSetOutput) ToStatefulSetOutputWithContext(ctx context.Context) StatefulSetOutput {
   415  	return o
   416  }
   417  
   418  // 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
   419  func (o StatefulSetOutput) ApiVersion() pulumi.StringPtrOutput {
   420  	return o.ApplyT(func(v *StatefulSet) pulumi.StringPtrOutput { return v.ApiVersion }).(pulumi.StringPtrOutput)
   421  }
   422  
   423  // 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
   424  func (o StatefulSetOutput) Kind() pulumi.StringPtrOutput {
   425  	return o.ApplyT(func(v *StatefulSet) pulumi.StringPtrOutput { return v.Kind }).(pulumi.StringPtrOutput)
   426  }
   427  
   428  // Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   429  func (o StatefulSetOutput) Metadata() metav1.ObjectMetaPtrOutput {
   430  	return o.ApplyT(func(v *StatefulSet) metav1.ObjectMetaPtrOutput { return v.Metadata }).(metav1.ObjectMetaPtrOutput)
   431  }
   432  
   433  // Spec defines the desired identities of pods in this set.
   434  func (o StatefulSetOutput) Spec() StatefulSetSpecPtrOutput {
   435  	return o.ApplyT(func(v *StatefulSet) StatefulSetSpecPtrOutput { return v.Spec }).(StatefulSetSpecPtrOutput)
   436  }
   437  
   438  // Status is the current status of Pods in this StatefulSet. This data may be out of date by some window of time.
   439  func (o StatefulSetOutput) Status() StatefulSetStatusPtrOutput {
   440  	return o.ApplyT(func(v *StatefulSet) StatefulSetStatusPtrOutput { return v.Status }).(StatefulSetStatusPtrOutput)
   441  }
   442  
   443  type StatefulSetArrayOutput struct{ *pulumi.OutputState }
   444  
   445  func (StatefulSetArrayOutput) ElementType() reflect.Type {
   446  	return reflect.TypeOf((*[]*StatefulSet)(nil)).Elem()
   447  }
   448  
   449  func (o StatefulSetArrayOutput) ToStatefulSetArrayOutput() StatefulSetArrayOutput {
   450  	return o
   451  }
   452  
   453  func (o StatefulSetArrayOutput) ToStatefulSetArrayOutputWithContext(ctx context.Context) StatefulSetArrayOutput {
   454  	return o
   455  }
   456  
   457  func (o StatefulSetArrayOutput) Index(i pulumi.IntInput) StatefulSetOutput {
   458  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *StatefulSet {
   459  		return vs[0].([]*StatefulSet)[vs[1].(int)]
   460  	}).(StatefulSetOutput)
   461  }
   462  
   463  type StatefulSetMapOutput struct{ *pulumi.OutputState }
   464  
   465  func (StatefulSetMapOutput) ElementType() reflect.Type {
   466  	return reflect.TypeOf((*map[string]*StatefulSet)(nil)).Elem()
   467  }
   468  
   469  func (o StatefulSetMapOutput) ToStatefulSetMapOutput() StatefulSetMapOutput {
   470  	return o
   471  }
   472  
   473  func (o StatefulSetMapOutput) ToStatefulSetMapOutputWithContext(ctx context.Context) StatefulSetMapOutput {
   474  	return o
   475  }
   476  
   477  func (o StatefulSetMapOutput) MapIndex(k pulumi.StringInput) StatefulSetOutput {
   478  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *StatefulSet {
   479  		return vs[0].(map[string]*StatefulSet)[vs[1].(string)]
   480  	}).(StatefulSetOutput)
   481  }
   482  
   483  func init() {
   484  	pulumi.RegisterInputType(reflect.TypeOf((*StatefulSetInput)(nil)).Elem(), &StatefulSet{})
   485  	pulumi.RegisterInputType(reflect.TypeOf((*StatefulSetArrayInput)(nil)).Elem(), StatefulSetArray{})
   486  	pulumi.RegisterInputType(reflect.TypeOf((*StatefulSetMapInput)(nil)).Elem(), StatefulSetMap{})
   487  	pulumi.RegisterOutputType(StatefulSetOutput{})
   488  	pulumi.RegisterOutputType(StatefulSetArrayOutput{})
   489  	pulumi.RegisterOutputType(StatefulSetMapOutput{})
   490  }