pub fn resolve_cluster(&self, ctx: &str, cluster: Option<String>) -> Result<(Cluster, Region)> {
        let reg = self.get_region(ctx)?;

        // 1. `get -r dev-uk -c kops-uk`
        // Most precise - just get what asked for.
        // region must exist because `ctx` is either a region or a contextAlias
        if let Some(c) = cluster {
            if let Some(c) = self.clusters.get(&c) {
                return Ok((c.clone(), reg));
            } else {
                bail!("Specified cluster '{}' does not exist in shipcat.conf", c);
            }
        }

        // 2. `get -r preprodca-blue`
        // Infer cluster from the one serving it (if only one)
        let candidates = self
            .clusters
            .values()
            .cloned()
            .filter(|v| v.regions.contains(&reg.name))
            .collect::<Vec<_>>();
        if candidates.len() != 1 {
            bail!(
                "Ambiguous context {} served by more than one cluster - please specify -c cluster",
                ctx
            );
        }
        Ok((candidates[0].clone(), reg))
    }
/// Work out the cluster from the kube config
///
/// Can be done unambiguously when cluster name is specified,
/// Otherwise we will find the first candidate cluster serving this context
/// and bail if there's more than one.
Work out the cluster from the kube config
Can be done unambiguously when cluster name is specified,
Otherwise we will find the first candidate cluster serving this context
and bail if there's more than one.
Work out the cluster from the kube config Can be done unambiguously when cluster name is specified Otherwise we will find the first candidate cluster serving this context and bail if there ' s more than one .
pub fn resolve_cluster(&self, ctx: &str, cluster: Option<String>) -> Result<(Cluster, Region)> {
        let reg = self.get_region(ctx)?;
        // 1. `get -r dev-uk -c kops-uk`
        // Most precise - just get what asked for.
        // region must exist because `ctx` is either a region or a contextAlias
        if let Some(c) = cluster {
            if let Some(c) = self.clusters.get(&c) {
                return Ok((c.clone(), reg));
            } else {
                bail!("Specified cluster '{}' does not exist in shipcat.conf", c);
            }
        }
        // 2. `get -r preprodca-blue`
        // Infer cluster from the one serving it (if only one)
        let candidates = self
            .clusters
            .values()
            .cloned()
            .filter(|v| v.regions.contains(&reg.name))
            .collect::<Vec<_>>();
        if candidates.len() != 1 {
            bail!(
                "Ambiguous context {} served by more than one cluster - please specify -c cluster",
                ctx
            );
        }
        Ok((candidates[0].clone(), reg))
    }
pub fn resolve_cluster ( & self , ctx : & str , cluster : Option < String > ) -> Result < ( Cluster , Region ) > { let reg = self . get_region ( ctx ) ? ; // 1. `get -r dev-uk -c kops-uk` // Most precise - just get what asked for. // region must exist because `ctx` is either a region or a contextAlias if let Some ( c ) = cluster { if let Some ( c ) = self . clusters . get ( & c ) { return Ok ( ( c . clone ( ) , reg ) ) ; } else { bail ! ( " " c ) ; } } // 2. `get -r preprodca-blue` // Infer cluster from the one serving it (if only one) let candidates = self . clusters . values ( ) . cloned ( ) . filter ( | v | v . regions . contains ( & reg . name ) ) . collect :: < Vec < _ > > ( ) ; if candidates . len ( ) != 1 { bail ! ( " " ctx ) ; } Ok ( ( candidates [ 0 ] . clone ( ) , reg ) ) }
Work out the cluster from the kube config
Can be done unambiguously when cluster name is specified,
Otherwise we will find the first candidate cluster serving this context
and bail if there's more than one.
Work out the cluster from the kube config Can be done unambiguously when cluster name is specified Otherwise we will find the first candidate cluster serving this context and bail if there ' s more than one .
&self
ctx
&str
cluster
Option<String>
&self
ctx
&str
cluster
Option<String>