...

Source file src/github.com/cert-manager/issuer-lib/internal/ssaclient/certificaterequest.go

Documentation: github.com/cert-manager/issuer-lib/internal/ssaclient

     1  /*
     2  Copyright 2023 The cert-manager Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ssaclient
    18  
    19  import (
    20  	"encoding/json"
    21  
    22  	cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	v1 "k8s.io/client-go/applyconfigurations/meta/v1"
    25  	"sigs.k8s.io/controller-runtime/pkg/client"
    26  )
    27  
    28  type certificateRequestStatusApplyConfiguration struct {
    29  	v1.TypeMetaApplyConfiguration    `json:",inline"`
    30  	*v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"`
    31  	Status                           *cmapi.CertificateRequestStatus `json:"status,omitempty"`
    32  }
    33  
    34  func GenerateCertificateRequestStatusPatch(
    35  	name string,
    36  	namespace string,
    37  	status *cmapi.CertificateRequestStatus,
    38  ) (cmapi.CertificateRequest, client.Patch, error) {
    39  	// This object is used to deduce the name & namespace + unmarshall the return value in
    40  	cr := cmapi.CertificateRequest{
    41  		ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
    42  	}
    43  
    44  	// This object is used to render the patch
    45  	b := &certificateRequestStatusApplyConfiguration{
    46  		ObjectMetaApplyConfiguration: &v1.ObjectMetaApplyConfiguration{},
    47  	}
    48  	b.WithName(name)
    49  	b.WithNamespace(namespace)
    50  	b.WithKind(cmapi.CertificateRequestKind)
    51  	b.WithAPIVersion(cmapi.SchemeGroupVersion.Identifier())
    52  	b.Status = status
    53  
    54  	encodedPatch, err := json.Marshal(b)
    55  	if err != nil {
    56  		return cr, nil, err
    57  	}
    58  
    59  	return cr, applyPatch{encodedPatch}, nil
    60  }
    61  

View as plain text