func (s *site) runNodesDeprovisionHook(ctx *operationContext) error {
	s.reportProgress(ctx, ops.ProgressEntry{
		State:      ops.ProgressStateInProgress,
		Completion: 50,
		Message:    "Running nodes deprovisioning hook",
	})
	site, err := s.service.GetSite(s.key)
	if err != nil {
		return trace.Wrap(err)
	}
	// these are common environment variables valid for all deprovisioners
	vars := ctx.operation.Shrink.Vars
	env := map[string]string{
		constants.EnvTelekubeClusterName: vars.System.ClusterName,
	}
	job, err := s.app.Manifest.Hooks.NodesDeprovision.GetJob()
	if err != nil {
		return trace.Wrap(err)
	}
	request := app.HookRunRequest{
		Application: s.app.Package,
		Hook:        schema.HookNodesDeprovision,
		Env:         env,
	}
	secretParams := secretParams{
		token: vars.System.Token,
	}
	// set profiles and roles
	var profiles []string
	for profileName, servers := range site.ClusterState.ProfileMap() {
		profiles = append(profiles, profileName)
		// total desired count of the servers remains the same
		env[fmt.Sprintf(constants.EnvTelekubeNodeProfileCountTemplate, profileName)] = fmt.Sprintf("%v", len(servers))
	}
	env[constants.EnvTelekubeNodeProfiles] = strings.Join(profiles, ",")
	server := ctx.serversToRemove[0]
	switch provider := s.cloudProvider().(type) {
	case *aws:
		env[constants.EnvAWSInstancePrivateIP] = server.AdvertiseIP
		env[constants.EnvAWSInstancePrivateDNS] = server.Nodename
		// access parameters
		env[constants.EnvCloudProvider] = schema.ProviderAWS
		// setup parameters for VPC
		env[constants.EnvAWSRegion] = vars.AWS.Region
		env[constants.EnvAWSVPCID] = vars.AWS.VPCID
		// pass provider as mounted secrets
		secretParams.aws = &awsSecrets{
			accessKeyID:     provider.accessKey,
			secretAccessKey: provider.secretKey,
			sessionToken:    provider.sessionToken,
		}
	}
	err = s.runIntegrationHook(ctx, job, request, secretParams)
	if err != nil {
		ctx.Infof("Integration hook stopped with error: %v", trace.DebugReport(err))
		return trace.Wrap(err)
	}
	return nil
}
// runNodesDeprovisionHook runs hook to deprovison nodes
runNodesDeprovisionHook runs hook to deprovison nodes
// runNodesDeprovisionHook runs hook to deprovison nodes
func (s *site) runNodesDeprovisionHook(ctx *operationContext) error {
	s.reportProgress(ctx, ops.ProgressEntry{
		State:      ops.ProgressStateInProgress,
		Completion: 50,
		Message:    "Running nodes deprovisioning hook",
	})
	site, err := s.service.GetSite(s.key)
	if err != nil {
		return trace.Wrap(err)
	}
	vars := ctx.operation.Shrink.Vars
	env := map[string]string{
		constants.EnvTelekubeClusterName: vars.System.ClusterName,
	}
	job, err := s.app.Manifest.Hooks.NodesDeprovision.GetJob()
	if err != nil {
		return trace.Wrap(err)
	}
	request := app.HookRunRequest{
		Application: s.app.Package,
		Hook:        schema.HookNodesDeprovision,
		Env:         env,
	}
	secretParams := secretParams{
		token: vars.System.Token,
	}
	var profiles []string
	for profileName, servers := range site.ClusterState.ProfileMap() {
		profiles = append(profiles, profileName)
		env[fmt.Sprintf(constants.EnvTelekubeNodeProfileCountTemplate, profileName)] = fmt.Sprintf("%v", len(servers))
	}
	env[constants.EnvTelekubeNodeProfiles] = strings.Join(profiles, ",")
	server := ctx.serversToRemove[0]
	switch provider := s.cloudProvider().(type) {
	case *aws:
		env[constants.EnvAWSInstancePrivateIP] = server.AdvertiseIP
		env[constants.EnvAWSInstancePrivateDNS] = server.Nodename
		env[constants.EnvCloudProvider] = schema.ProviderAWS
		env[constants.EnvAWSRegion] = vars.AWS.Region
		env[constants.EnvAWSVPCID] = vars.AWS.VPCID
		secretParams.aws = &awsSecrets{
			accessKeyID:     provider.accessKey,
			secretAccessKey: provider.secretKey,
			sessionToken:    provider.sessionToken,
		}
	}
	err = s.runIntegrationHook(ctx, job, request, secretParams)
	if err != nil {
		ctx.Infof("Integration hook stopped with error: %v", trace.DebugReport(err))
		return trace.Wrap(err)
	}
	return nil
}
func ( s * site ) runNodesDeprovisionHook ( ctx * operationContext ) error { s . reportProgress ( ctx , ops . ProgressEntry { State : ops . ProgressStateInProgress , Completion : 50 , Message : " " , } ) site , err := s . service . GetSite ( s . key ) if err != nil { return trace . Wrap ( err ) } vars := ctx . operation . Shrink . Vars env := map [ string ] string { constants . EnvTelekubeClusterName : vars . System . ClusterName , } job , err := s . app . Manifest . Hooks . NodesDeprovision . GetJob ( ) if err != nil { return trace . Wrap ( err ) } request := app . HookRunRequest { Application : s . app . Package , Hook : schema . HookNodesDeprovision , Env : env , } secretParams := secretParams { token : vars . System . Token , } var profiles [ ] string for profileName , servers := range site . ClusterState . ProfileMap ( ) { profiles = append ( profiles , profileName ) env [ fmt . Sprintf ( constants . EnvTelekubeNodeProfileCountTemplate , profileName ) ] = fmt . Sprintf ( " " , len ( servers ) ) } env [ constants . EnvTelekubeNodeProfiles ] = strings . Join ( profiles , " " ) server := ctx . serversToRemove [ 0 ] switch provider := s . cloudProvider ( ) . ( type ) { case * aws : env [ constants . EnvAWSInstancePrivateIP ] = server . AdvertiseIP env [ constants . EnvAWSInstancePrivateDNS ] = server . Nodename env [ constants . EnvCloudProvider ] = schema . ProviderAWS env [ constants . EnvAWSRegion ] = vars . AWS . Region env [ constants . EnvAWSVPCID ] = vars . AWS . VPCID secretParams . aws = & awsSecrets { accessKeyID : provider . accessKey , secretAccessKey : provider . secretKey , sessionToken : provider . sessionToken , } } err = s . runIntegrationHook ( ctx , job , request , secretParams ) if err != nil { ctx . Infof ( " " , trace . DebugReport ( err ) ) return trace . Wrap ( err ) } return nil }
runNodesDeprovisionHook runs hook to deprovison nodes
runNodesDeprovisionHook runs hook to deprovison nodes
// these are common environment variables valid for all deprovisioners // set profiles and roles // total desired count of the servers remains the same // access parameters // setup parameters for VPC // pass provider as mounted secrets