Skip to content

Commit

Permalink
Make it work on Kubernetes
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Nov 5, 2021
1 parent 8856e1c commit eb71efb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/deploy/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
jobDiffOpts = cmp.Options{
cmpopts.IgnoreFields(batchv1.Job{}, "TypeMeta", "ObjectMeta", "Status"),
cmpopts.IgnoreFields(batchv1.JobSpec{}, "Selector", "TTLSecondsAfterFinished"),
cmpopts.IgnoreFields(v1.PodTemplateSpec{}, "ObjectMeta"),
cmpopts.IgnoreFields(corev1.PodTemplateSpec{}, "ObjectMeta"),
cmpopts.IgnoreFields(corev1.Container{}, "TerminationMessagePath", "TerminationMessagePolicy"),
cmpopts.IgnoreFields(corev1.PodSpec{}, "DNSPolicy", "SchedulerName", "SecurityContext"),
cmp.Comparer(func(x, y []corev1.EnvVar) bool {
Expand Down
3 changes: 1 addition & 2 deletions pkg/deploy/migrate-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ func MigrateCheResourcesLabels(nonCachingClient client.Client) bool {
noErrors := true

// Prepare selector
partOfCheLebelSelector := labels.NewSelector()
chePartOfSelectorRequirement, err := labels.NewRequirement(KubernetesPartOfLabelKey, selection.Equals, []string{CheEclipseOrg})
if err != nil {
logrus.Error("Failed to create selector for resources migration. All custom user objects are lost.")
return false
}
partOfCheLebelSelector.Add(*chePartOfSelectorRequirement)
partOfCheLebelSelector := labels.NewSelector().Add(*chePartOfSelectorRequirement)
listOptions := &client.ListOptions{
LabelSelector: partOfCheLebelSelector,
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/deploy/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func SyncTLSRoleToCluster(deployContext *DeployContext) (bool, error) {
},
Verbs: []string{
"create",
"get",
"patch",
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/deploy/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"crypto/x509"
"encoding/pem"
stderrors "errors"
"fmt"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -349,15 +350,22 @@ func K8sHandleCheTLSSecrets(deployContext *DeployContext) (reconcile.Result, err
}

domains := deployContext.CheCluster.Spec.K8s.IngressDomain + ",*." + deployContext.CheCluster.Spec.K8s.IngressDomain
if deployContext.CheCluster.Spec.Server.CheHost != "" && strings.Index(deployContext.CheCluster.Spec.Server.CheHost, deployContext.CheCluster.Spec.K8s.IngressDomain) == -1 && deployContext.CheCluster.Spec.Server.CheHostTLSSecret == "" {
if deployContext.CheCluster.Spec.Server.CheHost != "" && !strings.Contains(deployContext.CheCluster.Spec.Server.CheHost, deployContext.CheCluster.Spec.K8s.IngressDomain) && deployContext.CheCluster.Spec.Server.CheHostTLSSecret == "" {
domains += "," + deployContext.CheCluster.Spec.Server.CheHost
}

labels := ""
for labelName, labelValue := range GetLabels(deployContext.CheCluster, cheTLSSecretName) {
labels += fmt.Sprintf("%s=%s ", labelName, labelValue)
}

cheTLSSecretsCreationJobImage := DefaultCheTLSSecretsCreationJobImage()
jobEnvVars := map[string]string{
"DOMAIN": domains,
"CHE_NAMESPACE": deployContext.CheCluster.Namespace,
"CHE_SERVER_TLS_SECRET_NAME": cheTLSSecretName,
"CHE_CA_CERTIFICATE_SECRET_NAME": CheTLSSelfSignedCertificateSecretName,
"LABELS": labels,
}

done, err = SyncJobToCluster(deployContext, CheTLSJobName, CheTLSJobComponentName, cheTLSSecretsCreationJobImage, CheTLSJobServiceAccountName, jobEnvVars)
Expand Down

0 comments on commit eb71efb

Please sign in to comment.