-
Notifications
You must be signed in to change notification settings - Fork 32
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
31 changed files
with
2,544 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Build metadata-prefetch go binary | ||
FROM --platform=$BUILDPLATFORM golang:1.22.7 AS metadata-prefetch-builder | ||
|
||
ARG STAGINGVERSION | ||
|
||
WORKDIR /gcs-fuse-csi-driver | ||
ADD . . | ||
RUN make metadata-prefetch BINDIR=/bin | ||
|
||
# go/gke-releasing-policies#base-images | ||
FROM gke.gcr.io/debian-base:bookworm-v1.0.4-gke.2 AS debian | ||
|
||
# go/gke-releasing-policies#base-images | ||
FROM gcr.io/distroless/base-debian12 AS output-image | ||
|
||
# Copy existing binaries. | ||
COPY --from=debian /bin/ls /bin/ls | ||
|
||
# Copy dependencies. | ||
COPY --from=debian /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libselinux.so.1 | ||
COPY --from=debian /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 | ||
COPY --from=debian /lib/x86_64-linux-gnu/libpcre2-8.so.0 /lib/x86_64-linux-gnu/libpcre2-8.so.0 | ||
COPY --from=debian /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 | ||
|
||
# Validate dependencies | ||
FROM output-image AS validator-image | ||
COPY --from=debian /bin/bash /bin/bash | ||
COPY --from=debian /usr/bin/ldd /usr/bin/ldd | ||
COPY --from=debian /bin/grep /bin/grep | ||
SHELL ["/bin/bash", "-c"] | ||
RUN if ldd /bin/ls | grep "not found"; then echo "!!! Missing deps for ls command !!!" && exit 1; fi | ||
|
||
# Final image | ||
FROM output-image | ||
|
||
# Copy the built binaries | ||
COPY --from=metadata-prefetch-builder /bin/gcs-fuse-csi-driver-metadata-prefetch /gcs-fuse-csi-driver-metadata-prefetch | ||
|
||
ENTRYPOINT ["/gcs-fuse-csi-driver-metadata-prefetch"] |
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,102 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"os" | ||
"os/exec" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
const ( | ||
mountPathsLocation = "/volumes/" | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
flag.Parse() | ||
|
||
// Create cancellable context to pass into exec. | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
// Handle SIGTERM signal. | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGTERM) | ||
|
||
go func() { | ||
<-sigs | ||
klog.Info("Caught SIGTERM signal: Terminating...") | ||
cancel() | ||
|
||
os.Exit(0) // Exit gracefully | ||
}() | ||
|
||
// Start the "ls" command in the background. | ||
// All our volumes are mounted under the /volumes/ directory. | ||
cmd := exec.CommandContext(ctx, "ls", "-R", mountPathsLocation) | ||
cmd.Stdout = nil // Connects file descriptor to the null device (os.DevNull). | ||
|
||
// TODO(hime): We should research stratergies to parallelize ls execution and speed up cache population. | ||
err := cmd.Start() | ||
if err == nil { | ||
mountPaths, err := getDirectoryNames(mountPathsLocation) | ||
if err == nil { | ||
klog.Infof("Running ls on mountPath(s): %s", strings.Join(mountPaths, ", ")) | ||
} else { | ||
klog.Warningf("failed to get mountPaths: %v", err) | ||
} | ||
|
||
err = cmd.Wait() | ||
if err != nil { | ||
klog.Errorf("Error while executing ls command: %v", err) | ||
} else { | ||
klog.Info("Metadata prefetch complete") | ||
} | ||
} else { | ||
klog.Errorf("Error starting ls command: %v.", err) | ||
} | ||
|
||
klog.Info("Going to sleep...") | ||
|
||
// Keep the process running. | ||
select {} | ||
} | ||
|
||
// getDirectoryNames returns a list of strings representing the names of | ||
// the directories within the provided path. | ||
func getDirectoryNames(dirPath string) ([]string, error) { | ||
directories := []string{} | ||
items, err := os.ReadDir(dirPath) | ||
if err != nil { | ||
return directories, err | ||
} | ||
|
||
for _, item := range items { | ||
if item.IsDir() { | ||
directories = append(directories, item.Name()) | ||
} | ||
} | ||
|
||
return directories, nil | ||
} |
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
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
Oops, something went wrong.