-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Build the manager binary | ||
FROM golang:1.17 as builder | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY cmd/post-install/main.go cmd/post-install/main.go | ||
COPY pkg/ pkg/ | ||
COPY Makefile Makefile | ||
COPY hack/licenses licenses | ||
|
||
RUN make post-install-hook | ||
|
||
FROM busybox | ||
|
||
LABEL name="MongoDB Atlas Operator Post Install Hook" \ | ||
maintainer="support@mongodb.com" \ | ||
vendor="MongoDB" \ | ||
release="1" \ | ||
summary="MongoDB Atlas Operator Post Install Hook Image" | ||
|
||
WORKDIR / | ||
COPY --from=builder /workspace/bin/helm-post-install . | ||
COPY hack/licenses licenses | ||
|
||
ENTRYPOINT ["/helm-post-install"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
|
||
mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
pollingInterval = time.Second * 10 | ||
pollingDuration = time.Minute * 20 | ||
) | ||
|
||
func setupLogger() *zap.SugaredLogger { | ||
log, err := zap.NewDevelopment() | ||
if err != nil { | ||
zap.S().Errorf("Error building logger config: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
return log.Sugar() | ||
} | ||
|
||
// createK8sClient creates an in cluster client which can be used to fetch the current state of the AtlasCluster | ||
// resource. | ||
func createK8sClient() (client.Client, error) { | ||
restCfg, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
k8sClient, err := client.New(restCfg, client.Options{}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
k8sClient.Scheme().AddKnownTypes(schema.GroupVersion{Group: "atlas.mongodb.com", Version: "v1"}, &mdbv1.AtlasCluster{}, &mdbv1.AtlasClusterList{}) | ||
return k8sClient, nil | ||
} | ||
|
||
// isClusterReady returns a boolean indicating if the cluster has reached the ready state and is | ||
// ready to be used. | ||
func isClusterReady(logger *zap.SugaredLogger) (bool, error) { | ||
k8sClient, err := createK8sClient() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
ticker := time.NewTicker(pollingInterval) | ||
defer ticker.Stop() | ||
|
||
clusterName := os.Getenv("CLUSTER_NAME") | ||
namespace := os.Getenv("NAMESPACE") | ||
|
||
totalTime := time.Duration(0) | ||
for range ticker.C { | ||
if totalTime > pollingDuration { | ||
break | ||
} | ||
totalTime += pollingInterval | ||
|
||
atlasCluster := mdbv1.AtlasCluster{} | ||
if err := k8sClient.Get(context.TODO(), kube.ObjectKey(namespace, clusterName), &atlasCluster); err != nil { | ||
return false, err | ||
} | ||
|
||
// the atlas project has reached the ClusterReady state. | ||
for _, cond := range atlasCluster.Status.Conditions { | ||
if cond.Type == status.ClusterReadyType { | ||
if cond.Status == corev1.ConditionTrue { | ||
return true, nil | ||
} | ||
logger.Infof("Atlas Cluster %s is not yet ready", atlasCluster.Name) | ||
} | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
func main() { | ||
logger := setupLogger() | ||
|
||
clusterIsReady, err := isClusterReady(logger) | ||
if err != nil { | ||
logger.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
exitCode := 1 | ||
if clusterIsReady { | ||
exitCode = 0 | ||
} | ||
os.Exit(exitCode) | ||
} |
Submodule helm-charts
updated
2 files
+31 −0 | charts/atlas-cluster/templates/atlas-cluster.yaml | |
+8 −0 | charts/atlas-cluster/values.yaml |