Skip to content

Commit b56a5d1

Browse files
author
Oleg Sucharevich
committed
when using flag behind-firewall send the credentials to codefresh to be saved
1 parent f50d358 commit b56a5d1

File tree

2 files changed

+44
-50
lines changed

2 files changed

+44
-50
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.5
1+
1.2.0

pkg/kubernetes/kubernetes.go

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,59 +51,53 @@ func goOverContext(options *getOverContextOptions) error {
5151
var host string
5252
var ca []byte
5353
var token []byte
54-
if options.behindFirewall == false {
55-
clientCnf, e := options.config.ClientConfig()
56-
if e != nil {
57-
message := fmt.Sprintf("Failed to create config with error:\n%s", e)
58-
options.logger.Warn(message)
59-
return e
60-
}
61-
options.logger.Info("Created config for context")
62-
host = clientCnf.Host
54+
clientCnf, e := options.config.ClientConfig()
55+
if e != nil {
56+
message := fmt.Sprintf("Failed to create config with error:\n%s", e)
57+
options.logger.Warn(message)
58+
return e
59+
}
60+
options.logger.Info("Created config for context")
61+
host = clientCnf.Host
6362

64-
options.logger.Info("Creating rest client")
65-
clientset, e := kubeConfig.NewForConfig(clientCnf)
66-
if e != nil {
67-
message := fmt.Sprintf("Failed to create kubernetes client with error:\n%s", e)
68-
options.logger.Warn(message)
69-
return e
70-
}
71-
options.logger.Info("Created client set for context")
63+
options.logger.Info("Creating rest client")
64+
clientset, e := kubeConfig.NewForConfig(clientCnf)
65+
if e != nil {
66+
message := fmt.Sprintf("Failed to create kubernetes client with error:\n%s", e)
67+
options.logger.Warn(message)
68+
return e
69+
}
70+
options.logger.Info("Created client set for context")
7271

73-
options.logger.Info("Fetching service account from cluster")
74-
sa, e := clientset.CoreV1().ServiceAccounts(options.namespace).Get(options.serviceaccount, metav1.GetOptions{})
75-
if e != nil {
76-
message := fmt.Sprintf("Failed to get service account token with error:\n%s", e)
77-
options.logger.Warn(message)
78-
return e
79-
}
80-
if sa == nil {
81-
message := fmt.Sprintf("Service account: %s not found in namespace: %s", options.serviceaccount, options.namespace)
82-
options.logger.Warn(message)
83-
return fmt.Errorf(message)
84-
}
85-
secretName := string(sa.Secrets[0].Name)
86-
namespace := sa.Namespace
87-
options.logger.WithFields(log.Fields{
88-
"secret_name": secretName,
89-
"namespace": namespace,
90-
}).Info(fmt.Sprint("Found service account accisiated with secret"))
72+
options.logger.Info("Fetching service account from cluster")
73+
sa, e := clientset.CoreV1().ServiceAccounts(options.namespace).Get(options.serviceaccount, metav1.GetOptions{})
74+
if e != nil {
75+
message := fmt.Sprintf("Failed to get service account token with error:\n%s", e)
76+
options.logger.Warn(message)
77+
return e
78+
}
79+
if sa == nil {
80+
message := fmt.Sprintf("Service account: %s not found in namespace: %s", options.serviceaccount, options.namespace)
81+
options.logger.Warn(message)
82+
return fmt.Errorf(message)
83+
}
84+
secretName := string(sa.Secrets[0].Name)
85+
namespace := sa.Namespace
86+
options.logger.WithFields(log.Fields{
87+
"secret_name": secretName,
88+
"namespace": namespace,
89+
}).Info(fmt.Sprint("Found service account accisiated with secret"))
9190

92-
options.logger.Info("Fetching secret from cluster")
93-
secret, e := clientset.CoreV1().Secrets(namespace).Get(secretName, metav1.GetOptions{})
94-
if e != nil {
95-
message := fmt.Sprintf("Failed to get secrets with error:\n%s", e)
96-
options.logger.Warn(message)
97-
return e
98-
}
99-
token = secret.Data["token"]
100-
ca = secret.Data["ca.crt"]
101-
options.logger.Info(fmt.Sprint("Found secret"))
102-
} else {
103-
host = ""
104-
token = nil
105-
ca = nil
91+
options.logger.Info("Fetching secret from cluster")
92+
secret, e := clientset.CoreV1().Secrets(namespace).Get(secretName, metav1.GetOptions{})
93+
if e != nil {
94+
message := fmt.Sprintf("Failed to get secrets with error:\n%s", e)
95+
options.logger.Warn(message)
96+
return e
10697
}
98+
token = secret.Data["token"]
99+
ca = secret.Data["ca.crt"]
100+
options.logger.Info(fmt.Sprint("Found secret"))
107101

108102
options.logger.Info(fmt.Sprint("Creating cluster in Codefresh"))
109103
result, e := options.codefresh.Create(host, options.name, token, ca, options.behindFirewall)

0 commit comments

Comments
 (0)