/// <summary> /// Constructs a cluster proxy from a cluster login. /// </summary> /// <param name="kubeContext">The cluster context.</param> /// <param name="nodeProxyCreator"> /// The optional application supplied function that creates a node proxy /// given the node name, public address or FQDN, private address, and /// the node definition. /// </param> /// <param name="appendToLog">Optionally have logs appended to an existing log file rather than creating a new one.</param> /// <param name="defaultRunOptions"> /// Optionally specifies the <see cref="RunOptions"/> to be assigned to the /// <see cref="SshProxy{TMetadata}.DefaultRunOptions"/> property for the /// nodes managed by the cluster proxy. This defaults to <see cref="RunOptions.None"/>. /// </param> /// <remarks> /// The <paramref name="nodeProxyCreator"/> function will be called for each node in /// the cluster definition giving the application the chance to create the management /// proxy using the node's SSH credentials and also to specify logging. A default /// creator that doesn't initialize SSH credentials and logging is used if <c>null</c> /// is passed. /// </remarks> public ClusterProxy( KubeConfigContext kubeContext, NodeProxyCreator nodeProxyCreator = null, bool appendToLog = false, RunOptions defaultRunOptions = RunOptions.None) : this(kubeContext.Extension.ClusterDefinition, nodeProxyCreator, appendToLog : appendToLog, defaultRunOptions : defaultRunOptions) { Covenant.Requires <ArgumentNullException>(kubeContext != null); this.KubeContext = kubeContext; }
/// <summary> /// Constructs a cluster proxy from a cluster definition. /// </summary> /// <param name="clusterDefinition">The cluster definition.</param> /// <param name="nodeProxyCreator"> /// The application supplied function that creates a management proxy /// given the node name, public address or FQDN, private address, and /// the node definition. /// </param> /// <param name="appendToLog">Optionally have logs appended to an existing log file rather than creating a new one.</param> /// <param name="defaultRunOptions"> /// Optionally specifies the <see cref="RunOptions"/> to be assigned to the /// <see cref="SshProxy{TMetadata}.DefaultRunOptions"/> property for the /// nodes managed by the cluster proxy. This defaults to <see cref="RunOptions.None"/>. /// </param> /// <remarks> /// The <paramref name="nodeProxyCreator"/> function will be called for each node in /// the cluster definition giving the application the chance to create the node /// proxy using the node's SSH credentials and also to specify logging. A default /// creator that doesn't initialize SSH credentials and logging is used if <c>null</c> /// is passed. /// </remarks> public ClusterProxy( ClusterDefinition clusterDefinition, NodeProxyCreator nodeProxyCreator = null, bool appendToLog = false, RunOptions defaultRunOptions = RunOptions.None) { Covenant.Requires <ArgumentNullException>(clusterDefinition != null); if (nodeProxyCreator == null) { nodeProxyCreator = (name, publicAddress, privateAddress, append) => { var context = KubeHelper.CurrentContext; if (context != null && context.Extension != null) { return(new SshProxy <NodeDefinition>(name, publicAddress, privateAddress, context.Extension.SshCredentials)); } else { // Note that the proxy returned won't actually work because we're not // passing valid SSH credentials. This is useful for situations where // we need a cluster proxy for global things (like managing a hosting // environment) where we won't need access to specific cluster nodes. return(new SshProxy <NodeDefinition>(name, publicAddress, privateAddress, SshCredentials.None)); } }; } this.Definition = clusterDefinition; this.KubeContext = KubeHelper.CurrentContext; this.defaultRunOptions = defaultRunOptions; this.nodeProxyCreator = nodeProxyCreator; this.appendLog = appendToLog; CreateNodes(); }