Repository: helm/helm
File: pkg/kube/client.go (Go)

Code before:

		return nil
	}
}

func (c *Client) makeCreateApplyFunc(serverSideApply, forceConflicts, dryRun bool, fieldValidationDirective FieldValidationDirective) CreateApplyFunc {
	if serverSideApply {
		c.Logger().Debug(
			"using server-side apply for resource creation",
			slog.Bool("forceConflicts", forceConflicts),
			slog.Bool("dryRun", dryRun),
			slog.String("fieldValidationDirective", string(fieldValidationDirective)))

		return func(target *resource.Info) error {
			err := patchResourceServerSide(target, dryRun, forceConflicts, fieldValidationDirective)

			logger := c.Logger().With(
				slog.String("namespace", target.Namespace),
				slog.String("name", target.Name),
				slog.String("gvk", target.Mapping.GroupVersionKind.String()))
			if err != nil {
				logger.Debug("Error patching resource", slog.Any("error", err))
				return err
			}

			logger.Debug("Patched resource")

			return nil
		}
	}

	c.Logger().Debug("using client-side apply for resource creation")
	return createResource
}

// Create creates Kubernetes resources specified in the resource list.
func (c *Client) Create(resources ResourceList, options ...ClientCreateOption) (*Result, error) {
	c.Logger().Debug("creating resource(s)", "resources", len(resources))

	createOptions := clientCreateOptions{
		serverSideApply:          true, // Default to server-side apply
		fieldValidationDirective: FieldValidationDirectiveStrict,
	}

	errs := make([]error, 0, len(options))
	for _, o := range options {
		errs = append(errs, o(&createOptions))
	}
	if err := errors.Join(errs...); err != nil {
		return nil, fmt.Errorf("invalid client create option(s): %w", err)
	}

Review comment (suggestion):
I'd suggest to rename it to `Created resource` since it is `create` operation

Code after:

		return nil
	}
}

func (c *Client) makeCreateApplyFunc(serverSideApply, forceConflicts, dryRun bool, fieldValidationDirective FieldValidationDirective) CreateApplyFunc {
	if serverSideApply {
		c.Logger().Debug(
			"using server-side apply for resource creation",
			slog.Bool("forceConflicts", forceConflicts),
			slog.Bool("dryRun", dryRun),
			slog.String("fieldValidationDirective", string(fieldValidationDirective)))

		return func(target *resource.Info) error {
			err := patchResourceServerSide(target, dryRun, forceConflicts, fieldValidationDirective)

			logger := c.Logger().With(
				slog.String("namespace", target.Namespace),
				slog.String("name", target.Name),
				slog.String("gvk", target.Mapping.GroupVersionKind.String()))
			if err != nil {
				logger.Debug("Error creating resource via patch", slog.Any("error", err))
				return err
			}

			logger.Debug("Created resource via patch")

			return nil
		}
	}

	c.Logger().Debug("using client-side apply for resource creation")
	return createResource
}

// Create creates Kubernetes resources specified in the resource list.
func (c *Client) Create(resources ResourceList, options ...ClientCreateOption) (*Result, error) {
	c.Logger().Debug("creating resource(s)", "resources", len(resources))

	createOptions := clientCreateOptions{
		serverSideApply:          true, // Default to server-side apply
		fieldValidationDirective: FieldValidationDirectiveStrict,
	}

	errs := make([]error, 0, len(options))
	for _, o := range options {
		errs = append(errs, o(&createOptions))
	}
	if err := errors.Join(errs...); err != nil {
		return nil, fmt.Errorf("invalid client create option(s): %w", err)
	}