- 
                Notifications
    You must be signed in to change notification settings 
- Fork 181
WIP: use server-side-apply to update client-ca bundle #1918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            sanchezl
  wants to merge
  1
  commit into
  openshift:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
sanchezl:apply-ca-cm
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -35,6 +35,7 @@ import ( | |
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| applycorev1 "k8s.io/client-go/applyconfigurations/core/v1" | ||
| "k8s.io/client-go/informers" | ||
| "k8s.io/client-go/kubernetes" | ||
| coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
|  | @@ -402,22 +403,37 @@ func ManageClientCABundle(ctx context.Context, lister corev1listers.ConfigMapLis | |
| return nil, false, err | ||
| } | ||
|  | ||
| if creationRequired { | ||
| caBundleConfigMap, err = client.ConfigMaps(operatorclient.TargetNamespace).Create(ctx, requiredConfigMap, metav1.CreateOptions{}) | ||
| resourcehelper.ReportCreateEvent(recorder, caBundleConfigMap, err) | ||
| if err != nil { | ||
| return nil, false, err | ||
| patch := applycorev1.ConfigMap(caBundleConfigMapName, operatorclient.TargetNamespace) | ||
| patch.WithData(requiredConfigMap.Data) | ||
| tmp := &metav1.ObjectMeta{} | ||
| additionalAnnotations.EnsureTLSMetadataUpdate(tmp) | ||
| patch.WithAnnotations(tmp.Annotations) | ||
|  | ||
| if creationRequired || updateRequired { | ||
|  | ||
| result, err := client.ConfigMaps(operatorclient.TargetNamespace).Apply(ctx, patch, metav1.ApplyOptions{Force: true, FieldManager: "cluster-kube-apiserver-operator"}) | ||
|  | ||
| // emit events | ||
| if (result != nil && result.ResourceVersion == "1") || creationRequired { | ||
| // either the configmap was created or we expected it to be created and it failed | ||
| resourcehelper.ReportCreateEvent(recorder, caBundleConfigMap, err) | ||
| } else { | ||
| // an existing configmap was updated, even if we expected it to be created | ||
| resourcehelper.ReportUpdateEvent(recorder, caBundleConfigMap, err) | ||
| } | ||
| 
      Comment on lines
    
      +417
     to 
      423
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC apply responses will have HTTP status 201 if it caused the resource to be created and 200 otherwise. That would be 100% correct for cases where you get a response vs. a prediction based on the cached state. | ||
| klog.V(2).Infof("Created client CA bundle configmap %s/%s", caBundleConfigMap.Namespace, caBundleConfigMap.Name) | ||
| return caBundleConfigMap, true, nil | ||
| } else if updateRequired { | ||
| caBundleConfigMap, err = client.ConfigMaps(operatorclient.TargetNamespace).Update(ctx, requiredConfigMap, metav1.UpdateOptions{}) | ||
| resourcehelper.ReportUpdateEvent(recorder, caBundleConfigMap, err) | ||
|  | ||
| // handle the err from the Apply call | ||
| if err != nil { | ||
| return nil, false, err | ||
| } | ||
| klog.V(2).Infof("Updated client CA bundle configmap %s/%s", caBundleConfigMap.Namespace, caBundleConfigMap.Name) | ||
| return caBundleConfigMap, true, nil | ||
|  | ||
| if result.ResourceVersion == "1" { | ||
| klog.V(2).Infof("Created client CA bundle configmap %s/%s", result.Namespace, result.Name) | ||
| } else { | ||
| klog.V(2).Infof("Updated client CA bundle configmap %s/%s", result.Namespace, result.Name) | ||
| } | ||
|  | ||
| return result, true, nil | ||
| } | ||
|  | ||
| return caBundleConfigMap, false, nil | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're likely to make a mistake eventually if we need to keep this in sync with CombineCABundleConfigMapsOptimistically. Can we build the apply configuration purely from
requiredConfigMap?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I would image we would refactor the helpers to be a more appropriate, but for this POC just 'hacked' it in.