- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Listener: Use headless and metrics service #613
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
          
     Merged
      
        
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      47ac444
              
                updating according to decision
              
              
                Maleware 2add5ee
              
                remove unused input
              
              
                Maleware 439e178
              
                update test to also test for headless service
              
              
                Maleware 6f1ba14
              
                update function name and smoke test
              
              
                Maleware c0f4b58
              
                Updating function name everywhere
              
              
                Maleware 4298a8f
              
                Updating changelog
              
              
                Maleware 9f2a57f
              
                Moving services to own module, splitting up functions
              
              
                Maleware 7f34283
              
                Fixing rust docs
              
              
                Maleware fa30fe4
              
                Update according to review
              
              
                Maleware 840cb82
              
                Fix function import
              
              
                Maleware 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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
|  | @@ -7,6 +7,7 @@ mod kerberos; | |
| mod listener; | ||
| mod operations; | ||
| mod product_logging; | ||
| mod service; | ||
|  | ||
| use std::sync::Arc; | ||
|  | ||
|  | ||
  
    
      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 | 
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| use snafu::{ResultExt, Snafu}; | ||
| use stackable_operator::{ | ||
| builder::meta::ObjectMetaBuilder, | ||
| commons::product_image_selection::ResolvedProductImage, | ||
| k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec}, | ||
| kvp::{Label, Labels}, | ||
| role_utils::RoleGroupRef, | ||
| }; | ||
|  | ||
| use crate::{ | ||
| controller::build_recommended_labels, | ||
| crd::{APP_NAME, HIVE_PORT, HIVE_PORT_NAME, METRICS_PORT, METRICS_PORT_NAME, v1alpha1}, | ||
| }; | ||
|  | ||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("object is missing metadata to build owner reference"))] | ||
| ObjectMissingMetadataForOwnerRef { | ||
| source: stackable_operator::builder::meta::Error, | ||
| }, | ||
| #[snafu(display("failed to build Metadata"))] | ||
| MetadataBuild { | ||
| source: stackable_operator::builder::meta::Error, | ||
| }, | ||
| #[snafu(display("failed to build Labels"))] | ||
| LabelBuild { | ||
| source: stackable_operator::kvp::LabelError, | ||
| }, | ||
| } | ||
|  | ||
| /// The rolegroup [`Service`] is a headless service that allows direct access to the instances of a certain rolegroup | ||
| /// | ||
| /// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing. | ||
| pub fn build_rolegroup_headless_service( | ||
| hive: &v1alpha1::HiveCluster, | ||
| resolved_product_image: &ResolvedProductImage, | ||
| rolegroup: &RoleGroupRef<v1alpha1::HiveCluster>, | ||
| ) -> Result<Service, Error> { | ||
| let headless_service = Service { | ||
| metadata: ObjectMetaBuilder::new() | ||
| .name_and_namespace(hive) | ||
| // TODO: Use method on RoleGroupRef once op-rs is released | ||
| .name(rolegroup_headless_service_name(rolegroup)) | ||
| .ownerreference_from_resource(hive, None, Some(true)) | ||
| .context(ObjectMissingMetadataForOwnerRefSnafu)? | ||
| .with_recommended_labels(build_recommended_labels( | ||
| hive, | ||
| &resolved_product_image.app_version_label, | ||
| &rolegroup.role, | ||
| &rolegroup.role_group, | ||
| )) | ||
| .context(MetadataBuildSnafu)? | ||
| .build(), | ||
| spec: Some(ServiceSpec { | ||
| // Internal communication does not need to be exposed | ||
| type_: Some("ClusterIP".to_string()), | ||
| cluster_ip: Some("None".to_string()), | ||
| // Expecting same ports as on listener service, just as a headless, internal service | ||
| ports: Some(service_ports()), | ||
| selector: Some( | ||
| Labels::role_group_selector(hive, APP_NAME, &rolegroup.role, &rolegroup.role_group) | ||
| .context(LabelBuildSnafu)? | ||
| .into(), | ||
| ), | ||
| publish_not_ready_addresses: Some(true), | ||
| ..ServiceSpec::default() | ||
| }), | ||
| status: None, | ||
| }; | ||
| Ok(headless_service) | ||
| } | ||
|  | ||
| /// The rolegroup metrics [`Service`] is a service that exposes metrics and a prometheus scraping label | ||
| pub fn build_rolegroup_metrics_service( | ||
| hive: &v1alpha1::HiveCluster, | ||
| resolved_product_image: &ResolvedProductImage, | ||
| rolegroup: &RoleGroupRef<v1alpha1::HiveCluster>, | ||
| ) -> Result<Service, Error> { | ||
| let metrics_service = Service { | ||
| metadata: ObjectMetaBuilder::new() | ||
| .name_and_namespace(hive) | ||
| // TODO: Use method on RoleGroupRef once op-rs is released | ||
| .name(rolegroup_metrics_service_name(rolegroup)) | ||
| .ownerreference_from_resource(hive, None, Some(true)) | ||
| .context(ObjectMissingMetadataForOwnerRefSnafu)? | ||
| .with_recommended_labels(build_recommended_labels( | ||
| hive, | ||
| &resolved_product_image.app_version_label, | ||
| &rolegroup.role, | ||
| &rolegroup.role_group, | ||
| )) | ||
| .context(MetadataBuildSnafu)? | ||
| .with_label(Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?) | ||
| .build(), | ||
| spec: Some(ServiceSpec { | ||
| // Internal communication does not need to be exposed | ||
| type_: Some("ClusterIP".to_string()), | ||
| cluster_ip: Some("None".to_string()), | ||
| ports: Some(metrics_ports()), | ||
| selector: Some( | ||
| Labels::role_group_selector(hive, APP_NAME, &rolegroup.role, &rolegroup.role_group) | ||
| .context(LabelBuildSnafu)? | ||
| .into(), | ||
| ), | ||
| publish_not_ready_addresses: Some(true), | ||
| ..ServiceSpec::default() | ||
| }), | ||
| status: None, | ||
| }; | ||
| Ok(metrics_service) | ||
| } | ||
|  | ||
| /// Headless service for cluster internal purposes only. | ||
| // TODO: Move to operator-rs | ||
| pub fn rolegroup_headless_service_name(rolegroup: &RoleGroupRef<v1alpha1::HiveCluster>) -> String { | ||
| format!("{name}-headless", name = rolegroup.object_name()) | ||
| } | ||
|  | ||
| /// Headless metrics service exposes Prometheus endpoint only | ||
| // TODO: Move to operator-rs | ||
| pub fn rolegroup_metrics_service_name(rolegroup: &RoleGroupRef<v1alpha1::HiveCluster>) -> String { | ||
| format!("{name}-metrics", name = rolegroup.object_name()) | ||
| } | ||
|  | ||
| fn metrics_ports() -> Vec<ServicePort> { | ||
| vec![ServicePort { | ||
| name: Some(METRICS_PORT_NAME.to_string()), | ||
| port: METRICS_PORT.into(), | ||
| protocol: Some("TCP".to_string()), | ||
| ..ServicePort::default() | ||
| }] | ||
| } | ||
|  | ||
| fn service_ports() -> Vec<ServicePort> { | ||
| vec![ServicePort { | ||
| name: Some(HIVE_PORT_NAME.to_string()), | ||
| port: HIVE_PORT.into(), | ||
| protocol: Some("TCP".to_string()), | ||
| ..ServicePort::default() | ||
| }] | ||
| } | ||
  
    
      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
    
  
  
    
              
  
    
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.